优化mtr探测策略
告警日志增加业务名称、告警推送是否成功字段
This commit is contained in:
+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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user