出省流量统计增加立即执行、增加占比总计、不同运营商也统计.
磁盘统计HDD改为所有磁盘、速率单位改为 MB/s、流量图开始时间修正。 流量95值收益优化
This commit is contained in:
+1
-1
@@ -35,7 +35,7 @@ public class RmNetworkInterfaceChildController extends BaseController
|
||||
@PostMapping("/list")
|
||||
public AjaxResult list(@RequestBody RmNetworkInterfaceChild rmNetworkInterfaceChild)
|
||||
{
|
||||
List<RmNetworkInterfaceChild> list = rmNetworkInterfaceChildService.selectRmNetworkInterfaceChildList(rmNetworkInterfaceChild);
|
||||
List<RmNetworkInterfaceChild> list = rmNetworkInterfaceChildService.getNetworkInterfaceChildList(rmNetworkInterfaceChild);
|
||||
return success(list);
|
||||
}
|
||||
/**
|
||||
|
||||
+4
@@ -82,4 +82,8 @@ public class RmNetworkInterfaceChild extends BaseEntity
|
||||
private BigDecimal bandwidthResult;
|
||||
/** 有ipv4的标识 */
|
||||
private boolean ipv4Flag;
|
||||
/** 表名 */
|
||||
private String tableName;
|
||||
/** ping丢包率 */
|
||||
private Double pingDropped;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.tongran.rocketmq.domain.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* tcpdump探测策略对象 rm_tcpdump_config
|
||||
*
|
||||
* @author tongran
|
||||
* @date 2026-01-21
|
||||
*/
|
||||
@Data
|
||||
public class RmTcpdumpVo
|
||||
{
|
||||
/** 开启探测(0:否,1:是) */
|
||||
private Integer detectFlag;
|
||||
|
||||
/** 探测频率 */
|
||||
private String frequency;
|
||||
|
||||
/** 探测时间列表(多个时间用,分隔) */
|
||||
private String detectTimes;
|
||||
|
||||
}
|
||||
@@ -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更新结果存储
|
||||
|
||||
@@ -86,4 +86,6 @@ public interface InitialDiskInfoMapper
|
||||
List<InitialDiskInfo> selectInitialDiskInfoListByCondition(InitialDiskInfo condition);
|
||||
|
||||
InitialDiskInfo getDiskTotal(InitialDiskInfo initialDiskInfo);
|
||||
|
||||
List<InitialDiskInfo> sumDistInfoByCondition(InitialDiskInfo condition);
|
||||
}
|
||||
|
||||
+2
@@ -64,4 +64,6 @@ public interface RmNetworkInterfaceChildMapper
|
||||
void deleteRmNetworkInterfaceChildByClientId(String clientId);
|
||||
|
||||
void deleteByParentInterfaceName(@Param("clientId") String clientId, @Param("name") String name);
|
||||
|
||||
List<RmNetworkInterfaceChild> getNetworkInterfaceChildList(RmNetworkInterfaceChild rmNetworkInterfaceChild);
|
||||
}
|
||||
|
||||
+2
@@ -63,4 +63,6 @@ public interface IRmNetworkInterfaceChildService
|
||||
void deleteRmNetworkInterfaceChildByClientId(String clientId);
|
||||
|
||||
void deleteByParentInterfaceName(String clientId, String name);
|
||||
|
||||
List<RmNetworkInterfaceChild> getNetworkInterfaceChildList(RmNetworkInterfaceChild rmNetworkInterfaceChild);
|
||||
}
|
||||
|
||||
+85
-2
@@ -691,9 +691,16 @@ public class InitialBandwidthTrafficServiceImpl implements IInitialBandwidthTraf
|
||||
resultMap.put("cpuCores", cpuInfo.getCores());
|
||||
InitialDiskInfo diskInfo = new InitialDiskInfo();
|
||||
diskInfo.setClientId(initialBandwidthTraffic.getClientId());
|
||||
diskInfo.setType("HDD");
|
||||
InitialDiskInfo initialDiskInfo = diskInfoService.getDiskTotal(diskInfo);
|
||||
resultMap.put("diskTotal", initialDiskInfo.getTotal());
|
||||
if(initialDiskInfo != null){
|
||||
Long total = initialDiskInfo.getTotal();
|
||||
String totalStr = total + "G";
|
||||
if(total != null && total > 1024L){
|
||||
total = total / 1024;
|
||||
totalStr = total + "T";
|
||||
}
|
||||
resultMap.put("diskTotal", totalStr);
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
@@ -709,6 +716,82 @@ public class InitialBandwidthTrafficServiceImpl implements IInitialBandwidthTraf
|
||||
initialBandwidthTraffic.getStartTime(), initialBandwidthTraffic.getEndTime()
|
||||
);
|
||||
}
|
||||
// @Override
|
||||
// public Map<String, Object> pingDroppedEcharts(InitialBandwidthTraffic initialBandwidthTraffic) {
|
||||
// // 主网卡流量信息
|
||||
// List<InitialBandwidthTraffic> mainList = getListByTableName(initialBandwidthTraffic);
|
||||
// String originalName = initialBandwidthTraffic.getName();
|
||||
// String name = originalName;
|
||||
//
|
||||
// if (originalName != null && originalName.contains("(")) {
|
||||
// int index = originalName.indexOf("(");
|
||||
// name = originalName.substring(0, index);
|
||||
// }
|
||||
//
|
||||
// // 存储所有网卡的数据
|
||||
// Map<String, List<InitialBandwidthTraffic>> interfaceDataMap = new LinkedHashMap<>();
|
||||
// // 展示关系
|
||||
// Map<String, String> showRealation = new HashMap<>();
|
||||
//
|
||||
// // 添加主网卡数据
|
||||
// interfaceDataMap.put(name, mainList);
|
||||
// showRealation.put(name+"pingDropped", name+"的ping丢包率");
|
||||
//
|
||||
// boolean hasSubInterface = false;
|
||||
//
|
||||
// // 如果是Ethernet类型,查询子网卡
|
||||
// if(isEthernetInterface(name)){
|
||||
// RmNetworkInterfaceChild query = new RmNetworkInterfaceChild();
|
||||
// query.setClientId(initialBandwidthTraffic.getClientId());
|
||||
// query.setParentInterface(name);
|
||||
// List<RmNetworkInterfaceChild> children = rmNetworkInterfaceChildMapper.selectRmNetworkInterfaceChildList(query);
|
||||
// if(children != null && !children.isEmpty()){
|
||||
// hasSubInterface = true;
|
||||
// for (RmNetworkInterfaceChild child : children) {
|
||||
// InitialBandwidthTraffic childTraffic = new InitialBandwidthTraffic();
|
||||
// BeanUtils.copyProperties(initialBandwidthTraffic, childTraffic);
|
||||
// childTraffic.setName(child.getInterfaceName());
|
||||
// List<InitialBandwidthTraffic> childTrafficList = getListByTableName(childTraffic);
|
||||
//
|
||||
// if(childTrafficList != null && !childTrafficList.isEmpty()){
|
||||
// interfaceDataMap.put(child.getInterfaceName(), childTrafficList);
|
||||
// showRealation.put(child.getInterfaceName()+"pingDropped", child.getInterfaceName() + "的ping丢包率");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// // 获取ping丢包率图表数据
|
||||
// Map<String, Object> resultMap = EchartsMoreDataUtils.buildMultiInterfaceEchartsDataWithTotal(
|
||||
// interfaceDataMap,
|
||||
// InitialBandwidthTraffic::getCreateTime,
|
||||
// info -> info.getPingDropped() != null ? new BigDecimal(info.getPingDropped()) : null,
|
||||
// null, // 出站流量设为null,因为ping丢包率只有单向数据
|
||||
// initialBandwidthTraffic.getStartTime(),
|
||||
// initialBandwidthTraffic.getEndTime(),
|
||||
// BigDecimal.ONE // 使用1作为除数,因为ping丢包率通常是百分比,不需要单位转换
|
||||
// );
|
||||
//
|
||||
// // 如果有子网卡,添加总丢包率显示
|
||||
// if(hasSubInterface){
|
||||
// showRealation.put("totalPingDropped", name+"总ping丢包率");
|
||||
// }
|
||||
//
|
||||
// // 排序显示关系
|
||||
// Map<String, String> sortedShowRealation = EchartsMoreDataUtils.sortInterfaceMap(showRealation, name, hasSubInterface);
|
||||
// resultMap.put("showRealation", sortedShowRealation);
|
||||
//
|
||||
// // 添加单位信息(ping丢包率通常用百分比表示)
|
||||
// resultMap.put("unit", "%");
|
||||
//
|
||||
// return resultMap;
|
||||
//
|
||||
// } catch (Exception e){
|
||||
// e.printStackTrace();
|
||||
// return new HashMap<>();
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
public int countByClientIdAndTime(InitialBandwidthTraffic countQuery) {
|
||||
|
||||
+25
-3
@@ -210,6 +210,29 @@ public class InitialDiskInfoServiceImpl implements IInitialDiskInfoService
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
/**
|
||||
* 分表查询硬盘信息
|
||||
* @param queryParam
|
||||
* @return
|
||||
*/
|
||||
public List<InitialDiskInfo> sumDistInfoSharding(InitialDiskInfo queryParam) {
|
||||
// 获取涉及的表名
|
||||
Set<String> tableNames = TableSubUtil.getExistingTableNamesBetween(queryParam.getStartTime(), queryParam.getEndTime(), TABLE_PREFIX);
|
||||
|
||||
// 并行查询各表
|
||||
return tableNames.parallelStream()
|
||||
.flatMap(tableName -> {
|
||||
InitialDiskInfo condition = new InitialDiskInfo();
|
||||
condition.setTableName(tableName);
|
||||
condition.setClientId(queryParam.getClientId());
|
||||
condition.setName(queryParam.getName());
|
||||
condition.setType(queryParam.getType());
|
||||
condition.setStartTime(queryParam.getStartTime());
|
||||
condition.setEndTime(queryParam.getEndTime());
|
||||
return initialDiskInfoMapper.sumDistInfoByCondition(condition).stream();
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
/**
|
||||
* /dev/sda读写速率(KB/s)
|
||||
* @param initialDiskInfo
|
||||
@@ -251,9 +274,8 @@ public class InitialDiskInfoServiceImpl implements IInitialDiskInfoService
|
||||
}
|
||||
@Override
|
||||
public Map<String, Object> usedSpaceEcharts(InitialDiskInfo initialDiskInfo) {
|
||||
initialDiskInfo.setType("HDD");
|
||||
List<InitialDiskInfo> list = getDistInfoSharding(initialDiskInfo);
|
||||
String unit = "Kb";
|
||||
List<InitialDiskInfo> list = sumDistInfoSharding(initialDiskInfo);
|
||||
String unit = "KB";
|
||||
if(list != null && !list.isEmpty()){
|
||||
Long totalUsedSpace = 0L;
|
||||
for (InitialDiskInfo diskInfo : list) {
|
||||
|
||||
+9
@@ -1,6 +1,7 @@
|
||||
package com.tongran.rocketmq.service.impl;
|
||||
|
||||
import com.tongran.common.core.utils.DateUtils;
|
||||
import com.tongran.common.core.utils.TableSubUtil;
|
||||
import com.tongran.rocketmq.domain.RmNetworkInterfaceChild;
|
||||
import com.tongran.rocketmq.mapper.RmNetworkInterfaceChildMapper;
|
||||
import com.tongran.rocketmq.service.IRmNetworkInterfaceChildService;
|
||||
@@ -104,4 +105,12 @@ public class RmNetworkInterfaceChildServiceImpl implements IRmNetworkInterfaceCh
|
||||
public void deleteByParentInterfaceName(String clientId, String name) {
|
||||
rmNetworkInterfaceChildMapper.deleteByParentInterfaceName(clientId, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RmNetworkInterfaceChild> getNetworkInterfaceChildList(RmNetworkInterfaceChild rmNetworkInterfaceChild) {
|
||||
String tableName = TableSubUtil.getTableName(DateUtils.getNowDate(),"initial_bandwidth_traffic");
|
||||
rmNetworkInterfaceChild.setTableName(tableName);
|
||||
List<RmNetworkInterfaceChild> list = rmNetworkInterfaceChildMapper.getNetworkInterfaceChildList(rmNetworkInterfaceChild);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
+6
-5
@@ -6,6 +6,7 @@ import com.tongran.common.core.utils.DateUtils;
|
||||
import com.tongran.rocketmq.domain.DeviceMessage;
|
||||
import com.tongran.rocketmq.domain.RmTcpdumpConfig;
|
||||
import com.tongran.rocketmq.domain.vo.PolicyTypeVo;
|
||||
import com.tongran.rocketmq.domain.vo.RmTcpdumpVo;
|
||||
import com.tongran.rocketmq.mapper.RmTcpdumpConfigMapper;
|
||||
import com.tongran.rocketmq.model.ProducerMode;
|
||||
import com.tongran.rocketmq.producer.MessageProducer;
|
||||
@@ -66,11 +67,11 @@ public class RmTcpdumpConfigServiceImpl implements IRmTcpdumpConfigService
|
||||
rmTcpdumpConfigMapper.insertRmTcpdumpConfig(rmTcpdumpConfig);
|
||||
// 下发消息给agent
|
||||
PolicyTypeVo policyTypeVo = new PolicyTypeVo();
|
||||
if(rmTcpdumpConfig.getDetectFlag() == 1 && rmTcpdumpConfig.getDetectTimes() != null){
|
||||
policyTypeVo.setTcpdumpTimes(rmTcpdumpConfig.getDetectTimes());
|
||||
}else{
|
||||
policyTypeVo.setTcpdumpTimes("");
|
||||
}
|
||||
RmTcpdumpVo rmTcpdumpVo = new RmTcpdumpVo();
|
||||
rmTcpdumpVo.setDetectFlag(rmTcpdumpConfig.getDetectFlag());
|
||||
rmTcpdumpVo.setFrequency(rmTcpdumpConfig.getFrequency());
|
||||
rmTcpdumpVo.setDetectTimes(rmTcpdumpConfig.getDetectTimes()==null?"":rmTcpdumpConfig.getDetectTimes());
|
||||
policyTypeVo.setTcpdumpTimes(JSONObject.toJSONString(rmTcpdumpVo));
|
||||
MessageProducer messageProducer = new MessageProducer();
|
||||
String configJson = JSONObject.toJSONString(policyTypeVo);
|
||||
DeviceMessage message = new DeviceMessage();
|
||||
|
||||
Reference in New Issue
Block a user