From 7d26d2fb3b169dc3d0e82526fef75f51b759e286 Mon Sep 17 00:00:00 2001 From: gaoyutao Date: Mon, 1 Dec 2025 18:15:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96mtr=E6=8E=A2=E6=B5=8B?= =?UTF-8?q?=E7=AD=96=E7=95=A5=E3=80=81=E5=A2=9E=E5=8A=A0ipv6=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/core/utils/EchartsDataUtils.java | 7 +- .../mtragent/domain/RmMtrProbeResult.java | 2 + .../mtragent/handler/MessageHandler.java | 1 + .../impl/RmMtrProbeResultServiceImpl.java | 5 + .../mtragent/RmMtrProbeResultMapper.xml | 45 ++-- .../RmResourceRegistrationServiceImpl.java | 6 + .../system/EpsInitialTrafficDataMapper.xml | 1 + .../domain/InitialBandwidthTraffic.java | 20 ++ .../domain/InitialBandwidthTrafficTemp.java | 194 ++---------------- .../rocketmq/handler/MessageHandler.java | 81 ++++++-- 10 files changed, 150 insertions(+), 212 deletions(-) diff --git a/tongran-common/tongran-common-core/src/main/java/com/tongran/common/core/utils/EchartsDataUtils.java b/tongran-common/tongran-common-core/src/main/java/com/tongran/common/core/utils/EchartsDataUtils.java index 9eaef29..dd43f2b 100644 --- a/tongran-common/tongran-common-core/src/main/java/com/tongran/common/core/utils/EchartsDataUtils.java +++ b/tongran-common/tongran-common-core/src/main/java/com/tongran/common/core/utils/EchartsDataUtils.java @@ -206,12 +206,7 @@ public class EchartsDataUtils { return ""; } - // 其他字段:第一个点补0,其他点补null - if (timeIndex == 0) { - return 0; - } else { - return null; - } + return null; } /** diff --git a/tongran-modules/tongran-mtragent/src/main/java/com/tongran/mtragent/domain/RmMtrProbeResult.java b/tongran-modules/tongran-mtragent/src/main/java/com/tongran/mtragent/domain/RmMtrProbeResult.java index b7ce32b..7748f24 100644 --- a/tongran-modules/tongran-mtragent/src/main/java/com/tongran/mtragent/domain/RmMtrProbeResult.java +++ b/tongran-modules/tongran-mtragent/src/main/java/com/tongran/mtragent/domain/RmMtrProbeResult.java @@ -44,6 +44,8 @@ public class RmMtrProbeResult extends BaseEntity private String startTime; /** 结束时间 */ private String endTime; + /** 每跳分析结果 */ + private String hopResult; diff --git a/tongran-modules/tongran-mtragent/src/main/java/com/tongran/mtragent/handler/MessageHandler.java b/tongran-modules/tongran-mtragent/src/main/java/com/tongran/mtragent/handler/MessageHandler.java index a759794..3d3ac4e 100644 --- a/tongran-modules/tongran-mtragent/src/main/java/com/tongran/mtragent/handler/MessageHandler.java +++ b/tongran-modules/tongran-mtragent/src/main/java/com/tongran/mtragent/handler/MessageHandler.java @@ -105,6 +105,7 @@ public class MessageHandler { rmMtrProbeResult.setMtrClientId(mtrClientId); rmMtrProbeResult.setPublicIp(mtrResultVo.getTargetIp()); rmMtrProbeResult.setPacketLossRate(new BigDecimal(mtrResultVo.getFinalLossPercent())); + rmMtrProbeResult.setHopResult(JSONObject.toJSONString(mtrResultVo.getHopInfos())); rmMtrProbeResultList.add(rmMtrProbeResult); AllMtrClient allMtrClient = new AllMtrClient(); BeanUtils.copyProperties(rmMtrProbeResult, allMtrClient); diff --git a/tongran-modules/tongran-mtragent/src/main/java/com/tongran/mtragent/service/impl/RmMtrProbeResultServiceImpl.java b/tongran-modules/tongran-mtragent/src/main/java/com/tongran/mtragent/service/impl/RmMtrProbeResultServiceImpl.java index 8c45723..dba82c9 100644 --- a/tongran-modules/tongran-mtragent/src/main/java/com/tongran/mtragent/service/impl/RmMtrProbeResultServiceImpl.java +++ b/tongran-modules/tongran-mtragent/src/main/java/com/tongran/mtragent/service/impl/RmMtrProbeResultServiceImpl.java @@ -207,6 +207,11 @@ public class RmMtrProbeResultServiceImpl implements IRmMtrProbeResultService info != null && info.getPacketLossRate() != null ? info.getPacketLossRate() : 0); + // 每一跳的分析结果 + extractors.put("deployDevice", info -> + info != null && info.getHopResult() != null ? + info.getHopResult() : + null); Map resultMap = EchartsDataUtils.buildEchartsDataAutoPadding( list, RmMtrProbeResult::getCreateTime, extractors, rmMtrProbeResult.getStartTime(), rmMtrProbeResult.getEndTime() ); diff --git a/tongran-modules/tongran-mtragent/src/main/resources/mapper/mtragent/RmMtrProbeResultMapper.xml b/tongran-modules/tongran-mtragent/src/main/resources/mapper/mtragent/RmMtrProbeResultMapper.xml index 3e71d9e..9b305ad 100644 --- a/tongran-modules/tongran-mtragent/src/main/resources/mapper/mtragent/RmMtrProbeResultMapper.xml +++ b/tongran-modules/tongran-mtragent/src/main/resources/mapper/mtragent/RmMtrProbeResultMapper.xml @@ -3,7 +3,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - + @@ -14,22 +14,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + - select id, mtr_client_id, client_id, public_ip, packet_loss_rate, create_time, update_time, create_by, update_by from rm_mtr_probe_result + select id, mtr_client_id, client_id, public_ip, packet_loss_rate, create_time, update_time, create_by, update_by, hop_result from rm_mtr_probe_result - + SELECT id, mtr_client_id, client_id, public_ip, packet_loss_rate, - create_time, update_time, create_by, update_by + create_time, update_time, create_by, update_by, hop_result FROM ${tableName} diff --git a/tongran-modules/tongran-system/src/main/java/com/tongran/system/service/impl/RmResourceRegistrationServiceImpl.java b/tongran-modules/tongran-system/src/main/java/com/tongran/system/service/impl/RmResourceRegistrationServiceImpl.java index c0a9da9..82f3694 100644 --- a/tongran-modules/tongran-system/src/main/java/com/tongran/system/service/impl/RmResourceRegistrationServiceImpl.java +++ b/tongran-modules/tongran-system/src/main/java/com/tongran/system/service/impl/RmResourceRegistrationServiceImpl.java @@ -687,6 +687,12 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio updateData.setAgentVersion(rmResourceRegistration.getAgentVersion()); needUpdate = true; } + if(exits.getHardwareSn() == null || + !StringUtils.equals(rmResourceRegistration.getHardwareSn(),exits.getHardwareSn())){ + // 如果服务器已注册 增加SN信息 + updateData.setHardwareSn(rmResourceRegistration.getHardwareSn()); + needUpdate = true; + } if(needUpdate){ updateData.setId(exits.getId()); rmResourceRegistrationMapper.updateRmResourceRegistration(updateData); diff --git a/tongran-modules/tongran-system/src/main/resources/mapper/system/EpsInitialTrafficDataMapper.xml b/tongran-modules/tongran-system/src/main/resources/mapper/system/EpsInitialTrafficDataMapper.xml index c629ce8..86438ca 100644 --- a/tongran-modules/tongran-system/src/main/resources/mapper/system/EpsInitialTrafficDataMapper.xml +++ b/tongran-modules/tongran-system/src/main/resources/mapper/system/EpsInitialTrafficDataMapper.xml @@ -73,6 +73,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" client_id VARCHAR(200) COMMENT '客户端ID', public_ip VARCHAR(45) COMMENT '公网IP地址', packet_loss_rate DECIMAL(5,2) COMMENT '丢包率(%)', + hop_result LONGTEXT COMMENT '每一跳解析结果(JSON形式)', create_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', create_by VARCHAR(64) COMMENT '创建人', diff --git a/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/InitialBandwidthTraffic.java b/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/InitialBandwidthTraffic.java index 715bf08..892743d 100644 --- a/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/InitialBandwidthTraffic.java +++ b/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/InitialBandwidthTraffic.java @@ -42,6 +42,8 @@ public class InitialBandwidthTraffic extends BaseEntity /** IPv4地址 */ @Excel(name = "IPv4地址") private String ipV4; + /** Ipv6 */ + private String ipV6; /** 入站丢包率(%) */ @Excel(name = "入站丢包率(%)") @@ -81,5 +83,23 @@ public class InitialBandwidthTraffic extends BaseEntity /** 总发送带宽 */ @Excel(name = "总发送带宽") private String totalOutSpeed; + /** IPv4接收流量 */ + private String ipv4InSpeed; + /** IPv4发送流量 */ + private String ipv4OutSpeed; + + /** IPv6接收流量 */ + private String ipv6InSpeed; + + /** IPv6发送流量 */ + private String ipv6OutSpeed; + /** IPv4接收总流量 */ + private String totalIpv4InSpeed; + /** IPv4发送总流量 */ + private String totalIpv4OutSpeed; + /** IPv6接收总流量 */ + private String totalIpv6InSpeed; + /** IPv6发送总流量 */ + private String totalIpv6OutSpeed; } diff --git a/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/InitialBandwidthTrafficTemp.java b/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/InitialBandwidthTrafficTemp.java index a413ab1..9896565 100644 --- a/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/InitialBandwidthTrafficTemp.java +++ b/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/InitialBandwidthTrafficTemp.java @@ -1,10 +1,10 @@ package com.tongran.rocketmq.domain; -import java.math.BigDecimal; -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; import com.tongran.common.core.annotation.Excel; import com.tongran.common.core.web.domain.BaseEntity; +import lombok.Data; + +import java.math.BigDecimal; /** * 初始带宽流量临时表对象 initial_bandwidth_traffic_temp @@ -12,6 +12,7 @@ import com.tongran.common.core.web.domain.BaseEntity; * @author gyt * @date 2025-11-05 */ +@Data public class InitialBandwidthTrafficTemp extends BaseEntity { private static final long serialVersionUID = 1L; @@ -74,179 +75,24 @@ public class InitialBandwidthTrafficTemp extends BaseEntity /** 总发送带宽(bit) */ @Excel(name = "总发送带宽(bit)") private String totalOutSpeed; + /** IPv4接收流量 */ + private String ipv4InSpeed; - public void setId(Long id) - { - this.id = id; - } + /** IPv4发送流量 */ + private String ipv4OutSpeed; - public Long getId() - { - return id; - } + /** IPv6接收流量 */ + private String ipv6InSpeed; - public void setName(String name) - { - this.name = name; - } + /** IPv6发送流量 */ + private String ipv6OutSpeed; + /** IPv4接收总流量 */ + private String totalIpv4InSpeed; + /** IPv4发送总流量 */ + private String totalIpv4OutSpeed; + /** IPv6接收总流量 */ + private String totalIpv6InSpeed; + /** IPv6发送总流量 */ + private String totalIpv6OutSpeed; - public String getName() - { - return name; - } - - public void setMac(String mac) - { - this.mac = mac; - } - - public String getMac() - { - return mac; - } - - public void setStatus(String status) - { - this.status = status; - } - - public String getStatus() - { - return status; - } - - public void setType(String type) - { - this.type = type; - } - - public String getType() - { - return type; - } - - public void setIpV4(String ipV4) - { - this.ipV4 = ipV4; - } - - public String getIpV4() - { - return ipV4; - } - - public void setInDropped(BigDecimal inDropped) - { - this.inDropped = inDropped; - } - - public BigDecimal getInDropped() - { - return inDropped; - } - - public void setOutDropped(BigDecimal outDropped) - { - this.outDropped = outDropped; - } - - public BigDecimal getOutDropped() - { - return outDropped; - } - - public void setInSpeed(String inSpeed) - { - this.inSpeed = inSpeed; - } - - public String getInSpeed() - { - return inSpeed; - } - - public void setOutSpeed(String outSpeed) - { - this.outSpeed = outSpeed; - } - - public String getOutSpeed() - { - return outSpeed; - } - - public void setSpeed(String speed) - { - this.speed = speed; - } - - public String getSpeed() - { - return speed; - } - - public void setDuplex(String duplex) - { - this.duplex = duplex; - } - - public String getDuplex() - { - return duplex; - } - - public void setClientId(String clientId) - { - this.clientId = clientId; - } - - public String getClientId() - { - return clientId; - } - - public void setTotalInSpeed(String totalInSpeed) - { - this.totalInSpeed = totalInSpeed; - } - - public String getTotalInSpeed() - { - return totalInSpeed; - } - - public void setTotalOutSpeed(String totalOutSpeed) - { - this.totalOutSpeed = totalOutSpeed; - } - - public String getTotalOutSpeed() - { - return totalOutSpeed; - } - - @Override - public String toString() { - return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) - .append("id", getId()) - .append("name", getName()) - .append("mac", getMac()) - .append("status", getStatus()) - .append("type", getType()) - .append("ipV4", getIpV4()) - .append("inDropped", getInDropped()) - .append("outDropped", getOutDropped()) - .append("inSpeed", getInSpeed()) - .append("outSpeed", getOutSpeed()) - .append("speed", getSpeed()) - .append("duplex", getDuplex()) - .append("createTime", getCreateTime()) - .append("updateTime", getUpdateTime()) - .append("createBy", getCreateBy()) - .append("updateBy", getUpdateBy()) - .append("clientId", getClientId()) - .append("totalInSpeed", getTotalInSpeed()) - .append("totalOutSpeed", getTotalOutSpeed()) - .toString(); - } } diff --git a/tongran-rocketmq/src/main/java/com/tongran/rocketmq/handler/MessageHandler.java b/tongran-rocketmq/src/main/java/com/tongran/rocketmq/handler/MessageHandler.java index cf3025c..13c6720 100644 --- a/tongran-rocketmq/src/main/java/com/tongran/rocketmq/handler/MessageHandler.java +++ b/tongran-rocketmq/src/main/java/com/tongran/rocketmq/handler/MessageHandler.java @@ -676,38 +676,83 @@ public class MessageHandler { interfaces.forEach(iface -> { iface.setClientId(clientId); iface.setCreateTime(createTime); - // 发送流量 + + // 设置总流量(转换为比特) iface.setTotalOutSpeed(dataProcessUtil.bytesToBits(iface.getOutSpeed())); - // 接收流量 iface.setTotalInSpeed(dataProcessUtil.bytesToBits(iface.getInSpeed())); + iface.setTotalIpv4OutSpeed(dataProcessUtil.bytesToBits(iface.getIpv4OutSpeed())); + iface.setTotalIpv4InSpeed(dataProcessUtil.bytesToBits(iface.getIpv4InSpeed())); + iface.setTotalIpv6OutSpeed(dataProcessUtil.bytesToBits(iface.getIpv6OutSpeed())); + iface.setTotalIpv6InSpeed(dataProcessUtil.bytesToBits(iface.getIpv6InSpeed())); + InitialBandwidthTrafficTemp tempInfo = tempMap.get(iface.getMac()); if (tempInfo != null) { - // 计算inSpeed + // 计算总流入速率 if (iface.getTotalInSpeed() != null && tempInfo.getTotalInSpeed() != null) { BigDecimal nowInSpeed = new BigDecimal(iface.getTotalInSpeed()); BigDecimal tempInSpeed = new BigDecimal(tempInfo.getTotalInSpeed()); BigDecimal inDiff = nowInSpeed.subtract(tempInSpeed); - - // 检查相减结果是否为非负数 if (inDiff.compareTo(BigDecimal.ZERO) >= 0) { iface.setInSpeed(inDiff.divide(divisor, 0, RoundingMode.HALF_UP).toString()); - }else{ + } else { iface.setInSpeed(null); } } - // 计算outSpeed + // 计算总流出速率 if (iface.getTotalOutSpeed() != null && tempInfo.getTotalOutSpeed() != null) { BigDecimal nowOutSpeed = new BigDecimal(iface.getTotalOutSpeed()); BigDecimal tempOutSpeed = new BigDecimal(tempInfo.getTotalOutSpeed()); BigDecimal outDiff = nowOutSpeed.subtract(tempOutSpeed); - - // 检查相减结果是否为非负数 if (outDiff.compareTo(BigDecimal.ZERO) >= 0) { iface.setOutSpeed(outDiff.divide(divisor, 0, RoundingMode.HALF_UP).toString()); - }else{ + } else { iface.setOutSpeed(null); } } + // 计算IPv4流入速率 + if (iface.getTotalIpv4InSpeed() != null && tempInfo.getTotalIpv4InSpeed() != null) { + BigDecimal nowIpv4In = new BigDecimal(iface.getTotalIpv4InSpeed()); + BigDecimal tempIpv4In = new BigDecimal(tempInfo.getTotalIpv4InSpeed()); + BigDecimal ipv4InDiff = nowIpv4In.subtract(tempIpv4In); + if (ipv4InDiff.compareTo(BigDecimal.ZERO) >= 0) { + iface.setIpv4InSpeed(ipv4InDiff.divide(divisor, 0, RoundingMode.HALF_UP).toString()); + } else { + iface.setIpv4InSpeed(null); + } + } + // 计算IPv4流出速率 + if (iface.getTotalIpv4OutSpeed() != null && tempInfo.getTotalIpv4OutSpeed() != null) { + BigDecimal nowIpv4Out = new BigDecimal(iface.getTotalIpv4OutSpeed()); + BigDecimal tempIpv4Out = new BigDecimal(tempInfo.getTotalIpv4OutSpeed()); + BigDecimal ipv4OutDiff = nowIpv4Out.subtract(tempIpv4Out); + if (ipv4OutDiff.compareTo(BigDecimal.ZERO) >= 0) { + iface.setIpv4OutSpeed(ipv4OutDiff.divide(divisor, 0, RoundingMode.HALF_UP).toString()); + } else { + iface.setIpv4OutSpeed(null); + } + } + // 计算IPv6流入速率 + if (iface.getTotalIpv6InSpeed() != null && tempInfo.getTotalIpv6InSpeed() != null) { + BigDecimal nowIpv6In = new BigDecimal(iface.getTotalIpv6InSpeed()); + BigDecimal tempIpv6In = new BigDecimal(tempInfo.getTotalIpv6InSpeed()); + BigDecimal ipv6InDiff = nowIpv6In.subtract(tempIpv6In); + if (ipv6InDiff.compareTo(BigDecimal.ZERO) >= 0) { + iface.setIpv6InSpeed(ipv6InDiff.divide(divisor, 0, RoundingMode.HALF_UP).toString()); + } else { + iface.setIpv6InSpeed(null); + } + } + // 计算IPv6流出速率 + if (iface.getTotalIpv6OutSpeed() != null && tempInfo.getTotalIpv6OutSpeed() != null) { + BigDecimal nowIpv6Out = new BigDecimal(iface.getTotalIpv6OutSpeed()); + BigDecimal tempIpv6Out = new BigDecimal(tempInfo.getTotalIpv6OutSpeed()); + BigDecimal ipv6OutDiff = nowIpv6Out.subtract(tempIpv6Out); + if (ipv6OutDiff.compareTo(BigDecimal.ZERO) >= 0) { + iface.setIpv6OutSpeed(ipv6OutDiff.divide(divisor, 0, RoundingMode.HALF_UP).toString()); + } else { + iface.setIpv6OutSpeed(null); + } + } } }); // 清空临时表对应server信息 @@ -716,18 +761,27 @@ public class MessageHandler { interfaces.forEach(iface -> { iface.setClientId(clientId); iface.setCreateTime(createTime); - // 总发送流量 + // 设置总流量(转换为比特) iface.setTotalOutSpeed(dataProcessUtil.bytesToBits(iface.getOutSpeed())); - // 总接收流量 iface.setTotalInSpeed(dataProcessUtil.bytesToBits(iface.getInSpeed())); + iface.setTotalIpv4OutSpeed(dataProcessUtil.bytesToBits(iface.getIpv4OutSpeed())); + iface.setTotalIpv4InSpeed(dataProcessUtil.bytesToBits(iface.getIpv4InSpeed())); + iface.setTotalIpv6OutSpeed(dataProcessUtil.bytesToBits(iface.getIpv6OutSpeed())); + iface.setTotalIpv6InSpeed(dataProcessUtil.bytesToBits(iface.getIpv6InSpeed())); + + // 首次采集,速率设为null iface.setInSpeed(null); iface.setOutSpeed(null); + iface.setIpv4InSpeed(null); + iface.setIpv4OutSpeed(null); + iface.setIpv6InSpeed(null); + iface.setIpv6OutSpeed(null); }); } InitialBandwidthTraffic data = new InitialBandwidthTraffic(); // 批量入库集合 data.setList(interfaces); - // 临时表 用来计算inSpeed outSeppd + // 临时表 用来计算流量速率 initialBandwidthTrafficTempService.batchInsertServerTemp(interfaces); // 初始流量数据入库 initialBandwidthTrafficService.batchInsert(data); @@ -963,6 +1017,7 @@ public class MessageHandler { RmResourceRegistrationRemote updateData = new RmResourceRegistrationRemote(); updateData.setClientId(message.getClientId()); updateData.setLogicalNodeId(heartbeat.getLogicalNode()); + updateData.setHardwareSn(heartbeat.getSn()); updateData.setOnlineStatus("1"); updateData.setAgentVersion(version); updateData.setOnboardTime(DateUtils.getNowDate());