增加出省流量占比过高告警

This commit is contained in:
gaoyutao
2026-02-05 11:17:21 +08:00
parent 5dd9004081
commit 0fb6a33f2e
4 changed files with 45 additions and 3 deletions
@@ -7,7 +7,8 @@ public enum AlarmTypeEnum {
服务器下线("1", "服务器下线"),
交换机下线("2", "交换机下线"),
CPU使用率高("4", "CPU使用率高"),
磁盘缺失("5", "磁盘缺失");
磁盘缺失("5", "磁盘缺失"),
出省流量占比过高("6", "出省流量占比过高");
private final String code;
private final String msg;
AlarmTypeEnum(String code, String msg){
@@ -4,7 +4,8 @@ import lombok.Getter;
@Getter
public enum ConditionItemEnum {
服务器CPU使用率("1", "服务器CPU使用率");
服务器CPU使用率("1", "服务器CPU使用率"),
出省流量占比过高("2", "出省流量占比过高");
private final String code;
private final String msg;
ConditionItemEnum(String code, String msg){
@@ -12,6 +12,7 @@ import com.tongran.common.security.utils.SecurityUtils;
import com.tongran.rocketmq.domain.*;
import com.tongran.rocketmq.domain.vo.*;
import com.tongran.rocketmq.enums.AlarmTypeEnum;
import com.tongran.rocketmq.enums.ConditionItemEnum;
import com.tongran.rocketmq.model.ProducerMode;
import com.tongran.rocketmq.producer.MessageProducer;
import com.tongran.rocketmq.service.*;
@@ -145,6 +146,8 @@ public class MessageHandler {
private IRmTcpdumpConfigService rmTcpdumpConfigService;
@Autowired
private SendAlarmPushUtil sendAlarmPushUtil;
@Autowired
private IRmAlarmThresholdService rmAlarmThresholdService;
/**
@@ -352,6 +355,43 @@ public class MessageHandler {
insertData.setClientId(message.getClientId());
insertData.setDescription(content.toString());
rmOutboundTrafficStatisticsService.insertRmOutboundTrafficStatistics(insertData);
// 查询告警阈值
RmAlarmThreshold thresholdQuery = new RmAlarmThreshold();
thresholdQuery.setAlarmType(AlarmTypeEnum.出省流量占比过高.getCode());
thresholdQuery.setConditionItem(ConditionItemEnum.出省流量占比过高.getCode());
List<RmAlarmThreshold> rmAlarmThresholdList = rmAlarmThresholdService.selectRmAlarmThresholdList(thresholdQuery);
if(rmAlarmThresholdList != null && !rmAlarmThresholdList.isEmpty()){
String operator = rmAlarmThresholdList.get(0).getCompareOperator();
BigDecimal threshold = rmAlarmThresholdList.get(0).getThresholdValue();
if(operator != null){
// 根据运算符1大于,2小于,3等于 判断是否进行告警
boolean shouldAlarm = false;
// 根据运算符判断是否进行告警
switch (operator) {
case "1": // 大于
shouldAlarm = totalRate.compareTo(threshold) > 0;
break;
case "2": // 小于
shouldAlarm = totalRate.compareTo(threshold) < 0;
break;
case "3": // 等于
shouldAlarm = totalRate.compareTo(threshold) == 0;
break;
default:
log.warn("未知的运算符: {}", operator);
}
if(shouldAlarm){
RmAlarmLog rmAlarmLog = new RmAlarmLog();
rmAlarmLog.setAlarmType(AlarmTypeEnum.出省流量占比过高.getCode());
rmAlarmLog.setClientId(message.getClientId());
rmAlarmLog.setAlarmTime(DateUtils.getNowDate());
rmAlarmLog.setAlarmContent("服务器" + message.getClientId() + "出省流量占比过高");
rmAlarmLogService.insertRmAlarmLog(rmAlarmLog);
// 推送消息
sendAlarmPushUtil.sendAlarmPush(rmAlarmLog, AlarmTypeEnum.出省流量占比过高.getMsg());
}
}
}
}
}
@@ -258,7 +258,7 @@ public class InitialSystemOtherCollectDataServiceImpl implements IInitialSystemO
Double memUsed = usedMemoryGBMap.get(item.getCreateTime());
if (memUsed != null) {
// 格式化保留一位小数
String formattedMemUsed = String.format("%.1f", memUsed);
String formattedMemUsed = String.format("%.1f", memUsed) + "GB";
item.setMemUsed(formattedMemUsed);
}
}