增加流量最高的进程流量采集,优化ping缓存。
This commit is contained in:
@@ -41,6 +41,8 @@ public enum MsgEnum {
|
||||
|
||||
网络上报重试("NET_RECOVER"),
|
||||
|
||||
业务网络上报("BUSINESS_NET"),
|
||||
|
||||
挂载上报("POINT"),
|
||||
|
||||
交换机上报("SWITCHBOARD"),
|
||||
|
||||
@@ -17,11 +17,12 @@ public class NetBusinessVO implements Serializable {
|
||||
private static final long serialVersionUID = 9L;
|
||||
|
||||
private String name; // 网卡名称
|
||||
private String mac; // mac地址
|
||||
private int pid; // 进程ID
|
||||
private String processName; // 进程名
|
||||
|
||||
private double inSpeed; // 累计接收字节数
|
||||
private double outSpeed; // 累计发送字节数
|
||||
private Long inSpeed; // 累计接收字节数
|
||||
private Long outSpeed; // 累计发送字节数
|
||||
|
||||
private int connectionCount; // 当前连接数
|
||||
|
||||
|
||||
@@ -24,9 +24,7 @@ import org.springframework.stereotype.Component;
|
||||
import javax.annotation.Resource;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@Component
|
||||
@@ -97,6 +95,8 @@ public class BusinessTasks {
|
||||
|
||||
@Resource
|
||||
private NetService netService;
|
||||
@Resource
|
||||
private NetBusinessService netBusinessService;
|
||||
|
||||
@Resource
|
||||
private SystemService systemService;
|
||||
@@ -261,9 +261,30 @@ public class BusinessTasks {
|
||||
if (Objects.nonNull(sessionManager.getSessionById(GlobalConfig.CLIENT_ID))) {
|
||||
// 发送网卡信息包
|
||||
String data = "";
|
||||
String businessData = "";
|
||||
List<NetVO> list = netService.netList(timestamp);
|
||||
if(CollectionUtil.isNotEmpty(list)){
|
||||
List<NetBusinessVO> businessNetList = netBusinessService.netList(timestamp);
|
||||
// 2. 优化MAC地址赋值(使用HashMap,避免重复分割)
|
||||
if (CollectionUtil.isNotEmpty(list) && CollectionUtil.isNotEmpty(businessNetList)) {
|
||||
// 构建网卡名到MAC的映射(一次性处理所有netVO)
|
||||
Map<String, String> macMap = new HashMap<>(list.size() * 2);
|
||||
for (NetVO net : list) {
|
||||
String name = net.getName();
|
||||
// 只分割一次,缓存结果
|
||||
int idx = name.indexOf('(');
|
||||
String pureName = idx > 0 ? name.substring(0, idx) : name;
|
||||
macMap.put(pureName, net.getMac());
|
||||
}
|
||||
|
||||
// 批量赋值MAC地址
|
||||
for (NetBusinessVO business : businessNetList) {
|
||||
String mac = macMap.get(business.getName());
|
||||
if (mac != null) {
|
||||
business.setMac(mac);
|
||||
}
|
||||
}
|
||||
data = JSONArray.toJSONString(list);
|
||||
businessData = JSONArray.toJSONString(businessNetList);
|
||||
}
|
||||
Message message = Message.builder().clientId(GlobalConfig.CLIENT_ID).dataType(MsgEnum.网络上报.getValue()).data(data).build();
|
||||
// 将本次流量存储到本地文件
|
||||
@@ -277,6 +298,9 @@ public class BusinessTasks {
|
||||
}
|
||||
sessionManager.writeAndFlush(sessionManager.getSessionById(GlobalConfig.CLIENT_ID).getChannel(), message);
|
||||
AssertLog.info("发送网络信息包={}",JSON.toJSONString(message));
|
||||
Message businessMessage = Message.builder().clientId(GlobalConfig.CLIENT_ID).dataType(MsgEnum.业务网络上报.getValue()).data(businessData).build();
|
||||
sessionManager.writeAndFlush(sessionManager.getSessionById(GlobalConfig.CLIENT_ID).getChannel(), businessMessage);
|
||||
AssertLog.info("发送业务网络信息包={}",JSON.toJSONString(businessMessage));
|
||||
}
|
||||
AssertLog.info("网络信息采集定时任务执行 - task #{} completed", count);
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ public class NetBusinessServiceImpl implements NetBusinessService {
|
||||
String[] parts = line.split("\\s+");
|
||||
if (parts.length >= 10) {
|
||||
String iface = parts[0].replace(":", "");
|
||||
if(iface.startsWith("lo")) continue;
|
||||
long recv = Long.parseLong(parts[1]); // 接收字节
|
||||
long sent = Long.parseLong(parts[9]); // 发送字节
|
||||
|
||||
|
||||
@@ -254,6 +254,8 @@ public class NetServiceImpl implements NetService {
|
||||
if(hasIpv4){
|
||||
startPingMonitorAsync(interfaceName, timestamp);
|
||||
netVO.setPingDropped(pingCache.get(interfaceName+(timestamp-300)));
|
||||
// 使用完清除,防止内存泄漏
|
||||
pingCache.remove(interfaceName+(timestamp-300));
|
||||
}
|
||||
// 设置协商速度和工作模式
|
||||
Map<String, String> ethtoolMap = getNetworkMode(net.getName());
|
||||
|
||||
Reference in New Issue
Block a user