优化mtr探测策略
告警日志增加业务名称、告警推送是否成功字段
This commit is contained in:
+2
-2
@@ -22,7 +22,7 @@
|
||||
//
|
||||
// // quartz参数
|
||||
// Properties prop = new Properties();
|
||||
// prop.put("org.quartz.scheduler.instanceName", "RuoyiScheduler");
|
||||
// prop.put("org.quartz.scheduler.instanceName", "TongRanScheduler");
|
||||
// prop.put("org.quartz.scheduler.instanceId", "AUTO");
|
||||
// // 线程池配置
|
||||
// prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
|
||||
@@ -42,7 +42,7 @@
|
||||
// prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_");
|
||||
// factory.setQuartzProperties(prop);
|
||||
//
|
||||
// factory.setSchedulerName("RuoyiScheduler");
|
||||
// factory.setSchedulerName("TongRanScheduler");
|
||||
// // 延时启动
|
||||
// factory.setStartupDelay(1);
|
||||
// factory.setApplicationContextSchedulerContextKey("applicationContextKey");
|
||||
|
||||
@@ -97,4 +97,20 @@
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.tongran.mtragent.domain.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* mtr探测策略配置对象 rm_mtr_policy_config
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-11-18
|
||||
*/
|
||||
@Data
|
||||
public class RmMtrPolicyConfigVo
|
||||
{
|
||||
/** 开始时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date startTime;
|
||||
|
||||
/** 结束时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date endTime;
|
||||
|
||||
/** 探测频率(秒) */
|
||||
private Long probeFrequency;
|
||||
/** clientId和ip对应集合 */
|
||||
private Map<String, List<String>> clientIdToIpsMap;
|
||||
}
|
||||
+17
-7
@@ -27,8 +27,10 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 设备消息处理器
|
||||
@@ -229,12 +231,18 @@ public class MessageHandler {
|
||||
if(!interfaces.isEmpty()) {
|
||||
RegisterMsgVo registerMsgVo = interfaces.get(0);
|
||||
String mtrClientId = registerMsgVo.getClientId();
|
||||
List<RmMtrPolicyConfig> mtrPolicyConfigList = rmMtrPolicyConfigService.getPoliciesForMtrClient(mtrClientId);
|
||||
if(mtrPolicyConfigList == null){
|
||||
mtrPolicyConfigList = new ArrayList<>();
|
||||
}
|
||||
List<RmMtrPolicyConfig> mtrPolicyConfigList = Optional.ofNullable(rmMtrPolicyConfigService.getPoliciesForMtrClient(mtrClientId))
|
||||
.orElse(new ArrayList<>());
|
||||
|
||||
List<RmMtrPolicyConfigVo> rmMtrPolicyConfigVoList = mtrPolicyConfigList.stream()
|
||||
.map(policy -> {
|
||||
RmMtrPolicyConfigVo vo = new RmMtrPolicyConfigVo();
|
||||
BeanUtils.copyProperties(policy, vo);
|
||||
return vo;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
// 构建mtrclient消息
|
||||
String mtrPolicyListStr = JSONObject.toJSONString(mtrPolicyConfigList);
|
||||
String mtrPolicyListStr = JSONObject.toJSONString(rmMtrPolicyConfigVoList);
|
||||
PolicyTypeVo policyTypeVo = new PolicyTypeVo();
|
||||
policyTypeVo.setMtrPolicys(mtrPolicyListStr);
|
||||
String configJson = JSONObject.toJSONString(policyTypeVo);
|
||||
@@ -247,9 +255,11 @@ public class MessageHandler {
|
||||
messageProducer.sendAsyncProducerMessage(
|
||||
producerMode.getAgentTopic(),
|
||||
"",
|
||||
"",
|
||||
"test",
|
||||
JSONObject.toJSONString(message)
|
||||
);
|
||||
int size = message.getData().getBytes(StandardCharsets.UTF_8).length;
|
||||
log.info("消息大小: {} 字节, {} KB", size, size/1024.0);
|
||||
} catch (Exception e) {
|
||||
log.error("发送mtr策略失败,mtrClientId: {}", mtrClientId, e);
|
||||
}
|
||||
@@ -332,7 +342,7 @@ public class MessageHandler {
|
||||
|
||||
// 只有达到3次心跳才执行数据库操作
|
||||
if (newHeartbeatCount >= 3) {
|
||||
log.info("客户端ID: {} 达到{}次心跳,开始执行数据库操作", clientId, newHeartbeatCount);
|
||||
log.debug("客户端ID: {} 达到{}次心跳,开始执行数据库操作", clientId, newHeartbeatCount);
|
||||
// agent更新结果存储
|
||||
RmMtrClientRegistration queryMtrClient = new RmMtrClientRegistration();
|
||||
queryMtrClient.setMtrClientId(clientId);
|
||||
|
||||
+2
-2
@@ -165,7 +165,7 @@ public class MessageProducer {
|
||||
try
|
||||
{
|
||||
Message msg = new Message(topic,tag,key, value.getBytes(RemotingHelper.DEFAULT_CHARSET));
|
||||
System.out.println("生产者发送消息:"+ JSON.toJSONString(value));
|
||||
log.info("生产者发送消息:"+ JSON.toJSONString(value));
|
||||
//设置消息延迟级别,我这里设置5,对应就是延时一分钟
|
||||
// "1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h"
|
||||
msg.setDelayTimeLevel(level);
|
||||
@@ -197,7 +197,7 @@ public class MessageProducer {
|
||||
try {
|
||||
//创建一个消息实例,指定主题、标签和消息体。
|
||||
Message msg = new Message(topic,tag,key, value.getBytes(RemotingHelper.DEFAULT_CHARSET));
|
||||
System.out.println("生产者发送消息:"+ JSON.toJSONString(value));
|
||||
log.info("生产者发送消息:"+ JSON.toJSONString(value));
|
||||
producer.send(msg,new SendCallback() {
|
||||
// 异步回调的处理
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -68,7 +68,7 @@ public class RmMtrClientRegistrationServiceImpl implements IRmMtrClientRegistrat
|
||||
List<RmMtrClientRegistration> list = rmMtrClientRegistrationMapper.selectRmMtrClientRegistrationList(rmMtrClientRegistration);
|
||||
for (RmMtrClientRegistration mtrClientRegistration : list) {
|
||||
// 处理网卡信息
|
||||
setNetworkMsg(rmMtrClientRegistration);
|
||||
setNetworkMsg(mtrClientRegistration);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
+2
@@ -150,6 +150,8 @@ public class RmMtrPolicyConfigServiceImpl implements IRmMtrPolicyConfigService
|
||||
public int updateRmMtrPolicyConfig(RmMtrPolicyConfig rmMtrPolicyConfig)
|
||||
{
|
||||
rmMtrPolicyConfig.setUpdateTime(DateUtils.getNowDate());
|
||||
// 给ip赋值
|
||||
setServerip(rmMtrPolicyConfig);
|
||||
return rmMtrPolicyConfigMapper.updateRmMtrPolicyConfig(rmMtrPolicyConfig);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ spring:
|
||||
server-addr: 172.16.15.52:8848
|
||||
# server-addr: 172.16.15.103:8848
|
||||
# namespace: public
|
||||
namespace: saas-local
|
||||
namespace: saas-prod
|
||||
username: nacos
|
||||
password: nacos
|
||||
# 配置文件格式
|
||||
|
||||
+11
-1
@@ -58,6 +58,12 @@ public class TableScheduleConfig {
|
||||
// 每天0点执行 计算95带宽值/日
|
||||
@Scheduled(cron = "0 4 0 * * ?", zone = "Asia/Shanghai")
|
||||
public void calculate95BandwidthDaily() {
|
||||
// 获取当月的日期范围
|
||||
LocalDate lastMonth = LocalDate.now(ZoneId.of("Asia/Shanghai"));
|
||||
LocalDate firstDayOfMonth = lastMonth.withDayOfMonth(1);
|
||||
LocalDate lastDayOfMonth = lastMonth.withDayOfMonth(lastMonth.lengthOfMonth());
|
||||
String monthlyStartTime = firstDayOfMonth.atStartOfDay().format(TIME_FORMAT);
|
||||
String monthlyEndTime = lastDayOfMonth.atTime(23, 59, 59).format(TIME_FORMAT);
|
||||
// 获取昨天的日期范围(北京时间)
|
||||
LocalDate yesterday = LocalDate.now(ZoneId.of("Asia/Shanghai")).minusDays(1);
|
||||
String dailyStartTime = yesterday.atStartOfDay().format(TIME_FORMAT); // 00:00:00
|
||||
@@ -77,7 +83,11 @@ public class TableScheduleConfig {
|
||||
.thenRun(() -> executeWithLog("交换机带宽1000",
|
||||
() -> initialSwitchInfoDetailsService.calculateSwitch95BandwidthDaily(initialSwitchInfoDetails, dailyStartTime, dailyEndTime, "1000")))
|
||||
.thenRun(() -> executeWithLog("交换机带宽1024",
|
||||
() -> initialSwitchInfoDetailsService.calculateSwitch95BandwidthDaily(initialSwitchInfoDetails, dailyStartTime, dailyEndTime, "1024")));
|
||||
() -> initialSwitchInfoDetailsService.calculateSwitch95BandwidthDaily(initialSwitchInfoDetails, dailyStartTime, dailyEndTime, "1024")))
|
||||
.thenRun(() -> calculateSwitchMonthlyBandwidth(monthlyStartTime, monthlyEndTime, "1000"))
|
||||
.thenRun(() -> calculateSwitchMonthlyBandwidth(monthlyStartTime, monthlyEndTime, "1024"))
|
||||
.thenRun(() -> calculateSwitchAvgMonthlyBandwidth(monthlyStartTime, monthlyEndTime, "1000"))
|
||||
.thenRun(() -> calculateSwitchAvgMonthlyBandwidth(monthlyStartTime, monthlyEndTime, "1024"));
|
||||
}
|
||||
// 每天5点04执行 计算金山95带宽值/日
|
||||
@Scheduled(cron = "0 4 5 * * ?", zone = "Asia/Shanghai")
|
||||
|
||||
+3
@@ -5,6 +5,7 @@ import com.tongran.common.core.annotation.Excel;
|
||||
import com.tongran.common.core.web.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -224,4 +225,6 @@ public class RmResourceRegistration extends BaseEntity
|
||||
private boolean businessEmpty;
|
||||
/** 逻辑节点空标识 */
|
||||
private boolean logicalNodeEmpty;
|
||||
/** 昨日95值 */
|
||||
private BigDecimal bandwidthResult;
|
||||
}
|
||||
-2
@@ -191,8 +191,6 @@ public class EpsNodeBandwidthServiceImpl implements IEpsNodeBandwidthService
|
||||
|
||||
// 4. 安全获取求和值
|
||||
BigDecimal sum95Daily = Optional.ofNullable(calculatedData.getBandwidth95Daily()).orElse(BigDecimal.ZERO);
|
||||
BigDecimal sumEffectiveBandwidth95Daily = Optional.ofNullable(calculatedData.getEffectiveBandwidth95Daily()).orElse(BigDecimal.ZERO);
|
||||
|
||||
// 5. 计算当月天数
|
||||
LocalDate monthTime;
|
||||
try {
|
||||
|
||||
+21
@@ -23,6 +23,8 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -68,6 +70,8 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
setNetWorkMsg(rmResourceRegistration);
|
||||
// set金山machineCode
|
||||
setMachineMsg(rmResourceRegistration);
|
||||
// set昨日95值
|
||||
setBandwidthYestoday(rmResourceRegistration);
|
||||
}
|
||||
return rmResourceRegistration;
|
||||
}
|
||||
@@ -93,6 +97,8 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
if(resourceRegistration.getClientId() != null){
|
||||
// 网卡信息
|
||||
setNetWorkMsg(resourceRegistration);
|
||||
// set昨日95值
|
||||
setBandwidthYestoday(resourceRegistration);
|
||||
}
|
||||
}
|
||||
if(rmResourceRegistration.getQueryParam() != null && !rmResourceRegistration.getQueryParam().trim().isEmpty()){
|
||||
@@ -297,6 +303,21 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
registration.setMachineCode(machineMsg.getMachineCode());
|
||||
}
|
||||
}
|
||||
|
||||
public void setBandwidthYestoday(RmResourceRegistration registration){
|
||||
// 查询昨日95值
|
||||
String yesterday = LocalDate.now().minusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));;
|
||||
Date yesterdayDate = DateUtils.parseDate(yesterday);
|
||||
EpsNodeBandwidth epsNodeBandwidth = new EpsNodeBandwidth();
|
||||
epsNodeBandwidth.setClientId(registration.getClientId());
|
||||
epsNodeBandwidth.setBandwidthType("1");
|
||||
epsNodeBandwidth.setCreateTime(yesterdayDate);
|
||||
List<EpsNodeBandwidth> nodeBandwidthList = epsNodeBandwidthMapper.selectEpsNodeBandwidthList(epsNodeBandwidth);
|
||||
if(nodeBandwidthList != null && !nodeBandwidthList.isEmpty()){
|
||||
EpsNodeBandwidth nodeBandwidth = nodeBandwidthList.get(0);
|
||||
registration.setBandwidthResult(nodeBandwidth.getBandwidthResult());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 新增资源注册
|
||||
*
|
||||
|
||||
@@ -21,7 +21,7 @@ spring:
|
||||
# 配置中心地址
|
||||
server-addr: 172.16.15.52:8848
|
||||
# server-addr: 172.16.15.103:8848
|
||||
namespace: saas-local
|
||||
namespace: saas-prod
|
||||
# namespace: public
|
||||
username: nacos
|
||||
password: nacos
|
||||
|
||||
+1
-2
@@ -230,8 +230,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</delete>
|
||||
|
||||
<select id="calculateAvg" parameterType="EpsNodeBandwidth" resultType="EpsNodeBandwidth">
|
||||
select sum(ifnull(bandwidth_95_daily,0)) bandwidth95Daily,
|
||||
sum(ifnull(effective_bandwidth_95_daily,0)) effectiveBandwidth95Daily
|
||||
select sum(ifnull(bandwidth_95_daily,0)) bandwidth95Daily
|
||||
from eps_node_bandwidth
|
||||
<where>
|
||||
<if test="startTime != null">
|
||||
|
||||
Reference in New Issue
Block a user