增加出省流量占比过高告警
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user