增加存储子网卡信息、修复子网卡流量递增问题
子网卡流量图合并
This commit is contained in:
@@ -89,6 +89,8 @@ public class MessageHandler {
|
||||
@Autowired
|
||||
private IRmNetworkInterfaceService rmNetworkInterfaceService;
|
||||
@Autowired
|
||||
private IRmNetworkInterfaceChildService rmNetworkInterfaceChildService;
|
||||
@Autowired
|
||||
private IRmMonitorPolicyService rmMonitorPolicyService;
|
||||
@Autowired
|
||||
private IRmDeploymentPolicyService rmDeploymentPolicyService;
|
||||
@@ -260,10 +262,10 @@ public class MessageHandler {
|
||||
temp.setClientId(clientId);
|
||||
List<InitialBandwidthTrafficTemp> tempList = initialBandwidthTrafficTempService.selectInitialBandwidthTrafficTempList(temp);
|
||||
if(!tempList.isEmpty()){
|
||||
// 1. 构建快速查找的Map
|
||||
// 1. 构建快速查找的Map,使用MAC地址+网卡名称作为唯一键
|
||||
Map<String, InitialBandwidthTrafficTemp> tempMap = tempList.stream()
|
||||
.collect(Collectors.toMap(
|
||||
InitialBandwidthTrafficTemp::getMac,
|
||||
tempItem -> generateKey(tempItem.getMac(), tempItem.getName()),
|
||||
Function.identity(),
|
||||
(existing, replacement) -> existing
|
||||
));
|
||||
@@ -290,7 +292,9 @@ public class MessageHandler {
|
||||
iface.setIpv6InSpeed(null);
|
||||
iface.setIpv6OutSpeed(null);
|
||||
|
||||
InitialBandwidthTrafficTemp tempInfo = tempMap.get(iface.getMac());
|
||||
// 使用MAC地址+网卡名称作为查找键
|
||||
String key = generateKey(iface.getMac(), iface.getName());
|
||||
InitialBandwidthTrafficTemp tempInfo = tempMap.get(key);
|
||||
if (tempInfo != null) {
|
||||
// 计算总流入速率
|
||||
if (iface.getTotalInSpeed() != null && tempInfo.getTotalInSpeed() != null) {
|
||||
@@ -387,6 +391,15 @@ public class MessageHandler {
|
||||
throw new RuntimeException("NET流量data数据为空");
|
||||
}
|
||||
}
|
||||
private String generateKey(String mac, String name) {
|
||||
if (mac == null) {
|
||||
mac = "";
|
||||
}
|
||||
if (name == null) {
|
||||
name = "";
|
||||
}
|
||||
return mac + "|" + name;
|
||||
}
|
||||
/**
|
||||
* docker数据入库
|
||||
* @param message
|
||||
@@ -1031,6 +1044,7 @@ public class MessageHandler {
|
||||
boolean isSingleInterface = networkInfoList.size() == 1;
|
||||
|
||||
for (NetworkInfo networkInfo : networkInfoList) {
|
||||
List<NetworkInfo> childList = networkInfo.getSubInterfaces();
|
||||
// 查询该网卡信息是否存在
|
||||
RmNetworkInterface queryParam = new RmNetworkInterface();
|
||||
queryParam.setClientId(clientId);
|
||||
@@ -1048,14 +1062,31 @@ public class MessageHandler {
|
||||
insertData.setBindIp("3");
|
||||
}
|
||||
rmNetworkInterfaceService.insertRmNetworkInterface(insertData);
|
||||
if(childList != null && !childList.isEmpty()){
|
||||
for (NetworkInfo info : childList) {
|
||||
RmNetworkInterfaceChild insertChild = new RmNetworkInterfaceChild();
|
||||
setNetworkInterfaceChildData(insertChild, info, clientId, networkInfo.getName());
|
||||
// 设置bindIp
|
||||
if (isSingleInterface) {
|
||||
insertChild.setBindIp("3");
|
||||
}
|
||||
rmNetworkInterfaceChildService.insertRmNetworkInterfaceChild(insertChild);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 更新网卡信息
|
||||
RmNetworkInterface oldInterfaceMsg = exits.get(0);
|
||||
|
||||
cleanChildOldRecords(clientId, networkInfo.getMac());
|
||||
// 判断是否需要创建新记录
|
||||
boolean needCreateNew = !StringUtils.equals(networkInfo.getName(), oldInterfaceMsg.getInterfaceName())
|
||||
|| !StringUtils.equals(networkInfo.getGateway(), oldInterfaceMsg.getGateway());
|
||||
|
||||
if(childList != null && !childList.isEmpty()){
|
||||
for (NetworkInfo info : childList) {
|
||||
RmNetworkInterfaceChild insertChild = new RmNetworkInterfaceChild();
|
||||
setNetworkInterfaceChildData(insertChild, info, clientId, networkInfo.getName());
|
||||
rmNetworkInterfaceChildService.insertRmNetworkInterfaceChild(insertChild);
|
||||
}
|
||||
}
|
||||
if(needCreateNew) {
|
||||
// 清理旧的历史数据
|
||||
cleanOldRecords(clientId, networkInfo.getMac());
|
||||
@@ -1095,6 +1126,20 @@ public class MessageHandler {
|
||||
networkInterface.setPublicIp(networkInfo.getPublicIp());
|
||||
networkInterface.setInterfaceType(networkInfo.getType());
|
||||
}
|
||||
private void setNetworkInterfaceChildData(RmNetworkInterfaceChild networkInterface, NetworkInfo networkInfo, String clientId, String parentName) {
|
||||
networkInterface.setClientId(clientId);
|
||||
networkInterface.setParentInterface(parentName);
|
||||
networkInterface.setIsp(networkInfo.getCarrier());
|
||||
networkInterface.setCity(networkInfo.getCity());
|
||||
networkInterface.setGateway(networkInfo.getGateway());
|
||||
networkInterface.setInterfaceName(networkInfo.getName());
|
||||
networkInterface.setIpv4Address(networkInfo.getIpv4());
|
||||
networkInterface.setIpv6Address(networkInfo.getIpv6());
|
||||
networkInterface.setMacAddress(networkInfo.getMac());
|
||||
networkInterface.setProvince(networkInfo.getProvince());
|
||||
networkInterface.setPublicIp(networkInfo.getPublicIp());
|
||||
networkInterface.setInterfaceType(networkInfo.getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理旧记录
|
||||
@@ -1111,7 +1156,20 @@ public class MessageHandler {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理旧记录
|
||||
*/
|
||||
private void cleanChildOldRecords(String clientId, String macAddress) {
|
||||
RmNetworkInterfaceChild childQuery = new RmNetworkInterfaceChild();
|
||||
childQuery.setClientId(clientId);
|
||||
childQuery.setMacAddress(macAddress);
|
||||
List<RmNetworkInterfaceChild> oldChildExits = rmNetworkInterfaceChildService.selectRmNetworkInterfaceChildList(childQuery);
|
||||
if(!oldChildExits.isEmpty()) {
|
||||
oldChildExits.forEach(oldMsg -> {
|
||||
rmNetworkInterfaceChildService.deleteRmNetworkInterfaceChildById(oldMsg.getId());
|
||||
});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 更新网卡信息
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user