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