出省流量统计增加立即执行、增加占比总计、不同运营商也统计.

磁盘统计HDD改为所有磁盘、速率单位改为 MB/s、流量图开始时间修正。
流量95值收益优化
This commit is contained in:
gaoyutao
2026-01-30 19:17:00 +08:00
parent 9809ae673c
commit f75a49474a
18 changed files with 369 additions and 38 deletions
@@ -129,6 +129,8 @@ public class MessageHandler {
@Autowired
private IRmOutboundTrafficStatisticsService rmOutboundTrafficStatisticsService;
@Autowired
private IRmTcpdumpConfigService rmTcpdumpConfigService;
@Autowired
private SendAlarmPushUtil sendAlarmPushUtil;
@@ -163,6 +165,8 @@ public class MessageHandler {
List<TcpdumpVo> tcpdumpVoList = JsonDataParser.parseJsonData(message.getData(), TcpdumpVo.class);
if(tcpdumpVoList != null && !tcpdumpVoList.isEmpty()){
String localProvince = "";
String localIsp = "";
boolean localHasFlag = false;
// 根据clientId查询省份信息
RmNetworkInterface networkInterfaceQuery = new RmNetworkInterface();
networkInterfaceQuery.setClientId(message.getClientId());
@@ -170,12 +174,26 @@ public class MessageHandler {
List<RmNetworkInterface> networkInfoList = rmNetworkInterfaceService.selectRmNetworkInterfaceList(networkInterfaceQuery);
if(networkInfoList != null && !networkInfoList.isEmpty()){
for (RmNetworkInterface rmNetworkInterface : networkInfoList) {
if(rmNetworkInterface.getProvince() != null){
if(rmNetworkInterface.getProvince() != null && rmNetworkInterface.getIsp() != null
&& ("1".equals(rmNetworkInterface.getBindIp()) || "3".equals(rmNetworkInterface.getBindIp()))){
localProvince = rmNetworkInterface.getProvince();
localIsp = rmNetworkInterface.getIsp();
localHasFlag = true;
break;
}
}
}
if(!localHasFlag){
// 查询子网卡
RmNetworkInterfaceChild childQuery = new RmNetworkInterfaceChild();
childQuery.setClientId(message.getClientId());
List<RmNetworkInterfaceChild> existingChildren = rmNetworkInterfaceChildService.selectRmNetworkInterfaceChildList(childQuery);
if(existingChildren != null && !existingChildren.isEmpty()){
RmNetworkInterfaceChild networkInfoChild = existingChildren.get(0);
localProvince = networkInfoChild.getProvince();
localIsp = networkInfoChild.getIsp();
}
}
// 计算总数量
Double totalCount = 0.0;
@@ -199,11 +217,15 @@ public class MessageHandler {
}
}
// 构建content内容 - 根据图片格式
// 构建content内容
StringBuilder content = new StringBuilder();
// 添加时间戳 - 根据图片格式
BigDecimal v4TotalRate = BigDecimal.ZERO;
BigDecimal v6TotalRate = BigDecimal.ZERO;
BigDecimal totalRate = BigDecimal.ZERO;
// 添加时间戳
content.append("时间:").append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())).append("\n");
int insertPosition = content.length();
int insertPositionV6 = content.length();
// 处理IPv4统计
if (!ipTypeMap.get("IPv4").isEmpty()) {
@@ -218,7 +240,8 @@ public class MessageHandler {
String province = locationInfo.get("province");
// 过滤本地省份和空值
if (province != null && operator != null && !localProvince.equals(province)) {
if (province != null && operator != null
&& (!localProvince.equals(province) || !localIsp.equals(operator))) {
String key = province + operator; // 根据图片格式,省份和运营商之间没有空格
double currentCount = v4StatMap.getOrDefault(key, 0.0);
v4StatMap.put(key, currentCount + tcpdumpVo.getCount());
@@ -229,12 +252,19 @@ public class MessageHandler {
// 计算百分比并排序
List<Map.Entry<String, Double>> sortedV4List = new ArrayList<>(v4StatMap.entrySet());
sortedV4List.sort((a, b) -> b.getValue().compareTo(a.getValue())); // 降序排序
// 先计算所有百分比并存储
for (Map.Entry<String, Double> entry : sortedV4List) {
BigDecimal percentage = new BigDecimal(entry.getValue() / totalCount * 100)
BigDecimal percentage = new BigDecimal(entry.getValue())
.divide(new BigDecimal(totalCount), 10, RoundingMode.HALF_UP)
.multiply(new BigDecimal(100))
.setScale(2, RoundingMode.HALF_UP);
content.append(entry.getKey()).append(": ").append(percentage).append("%\n");
v4TotalRate = v4TotalRate.add(percentage);
}
// 在记录的位置插入总计信息
content.insert(insertPosition, "IPv4总计占比: " + v4TotalRate + "%\n");
insertPositionV6 += ("IPv4总计占比: " + v4TotalRate + "%\n").length(); // 更新插入位置
totalRate = totalRate.add(v4TotalRate);
}
// 处理IPv6统计
@@ -250,7 +280,8 @@ public class MessageHandler {
String province = locationInfo.get("province");
// 过滤本地省份和空值
if (province != null && operator != null && !localProvince.equals(province)) {
if (province != null && operator != null
&& (!localProvince.equals(province) || !localIsp.equals(operator))) {
String key = province + operator; // 根据图片格式,省份和运营商之间没有空格
double currentCount = v6StatMap.getOrDefault(key, 0.0);
v6StatMap.put(key, currentCount + tcpdumpVo.getCount());
@@ -263,11 +294,19 @@ public class MessageHandler {
sortedV6List.sort((a, b) -> b.getValue().compareTo(a.getValue())); // 降序排序
for (Map.Entry<String, Double> entry : sortedV6List) {
BigDecimal percentage = new BigDecimal(entry.getValue() / totalCount * 100)
BigDecimal percentage = new BigDecimal(entry.getValue())
.divide(new BigDecimal(totalCount), 10, RoundingMode.HALF_UP)
.multiply(new BigDecimal(100))
.setScale(2, RoundingMode.HALF_UP);
content.append(entry.getKey()).append(": ").append(percentage).append("%\n");
v6TotalRate = v6TotalRate.add(percentage);
}
// 在更新后的位置插入IPv6总计
content.insert(insertPositionV6, "IPv6总计占比: " + v6TotalRate + "%\n");
totalRate = totalRate.add(v6TotalRate);
}
// 在更新后的位置插入IPv6总计
content.insert(insertPosition, "总占比: " + totalRate + "%\n");
RmOutboundTrafficStatistics insertData = new RmOutboundTrafficStatistics();
insertData.setClientId(message.getClientId());
insertData.setDescription(content.toString());
@@ -430,6 +469,18 @@ public class MessageHandler {
if(rows == 2){
// 注册成功,下发优先级为0的策略
rmMonitorPolicyService.issueDefaultPolicyByClientId(message.getClientId());
// 下发tcpdump默认策略
String detectTimes = "20:00:00";
RmTcpdumpConfig rmTcpdumpConfig = rmTcpdumpConfigService.selectRmTcpdumpConfigByClientId(clientId);
if(rmTcpdumpConfig != null){
detectTimes = detectTimes + "," + rmTcpdumpConfig.getDetectTimes();
}
RmTcpdumpConfig tcpdumpInsertData = new RmTcpdumpConfig();
tcpdumpInsertData.setClientId(clientId);
tcpdumpInsertData.setDetectFlag(1);
tcpdumpInsertData.setFrequency("1");
tcpdumpInsertData.setDetectTimes(detectTimes);
rmTcpdumpConfigService.insertRmTcpdumpConfig(tcpdumpInsertData);
// agent更新表插入数据
// 存储更新结果
// agent更新结果存储