挂载点数据增加已用存储空间字段

This commit is contained in:
gaoyutao
2026-01-27 19:08:16 +08:00
parent 3ef0aacf0c
commit 589c80fa6f
4 changed files with 60 additions and 83 deletions
@@ -12,14 +12,12 @@ 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.PushMethodEnum;
import com.tongran.rocketmq.model.ProducerMode;
import com.tongran.rocketmq.producer.MessageProducer;
import com.tongran.rocketmq.service.*;
import com.tongran.rocketmq.utils.DataProcessUtil;
import com.tongran.rocketmq.utils.JsonDataParser;
import com.tongran.rocketmq.utils.SendAlarmPushUtil;
import com.tongran.rocketmq.utils.WeChatWorkBot;
import com.tongran.system.api.RemoteRevenueConfigService;
import com.tongran.system.api.domain.*;
import lombok.extern.slf4j.Slf4j;
@@ -977,7 +975,7 @@ public class MessageHandler {
disk.setClientId(clientId);
disk.setCreateTime(createTime);
});
// // 关键:每个clientId有自己独立的key
// 关键:每个clientId有自己独立的key
// String diskCountKey = DISK_COUNT_PREFIX + clientId;
//
// // 1. 给这个客户端的所有磁盘次数+1
@@ -1032,7 +1030,7 @@ public class MessageHandler {
// rmAlarmLog.setAlarmType(AlarmTypeEnum.磁盘缺失.getCode());
// rmAlarmLog.setAlarmContent("服务器" + clientId + "磁盘缺失,磁盘名称:" + diskName);
// rmAlarmLogService.insertRmAlarmLog(rmAlarmLog);
// sendAlarmPushUtil.sendAlarmPush(rmAlarmLog);
// sendAlarmPushUtil.sendAlarmPush(rmAlarmLog, AlarmTypeEnum.磁盘缺失.getMsg());
//
// }
// } catch (NumberFormatException e) {
@@ -1501,41 +1499,8 @@ public class MessageHandler {
private void sendAlarmPush(RmAlarmLog rmAlarmLog, boolean isSwitch) {
String alarmTypeCode = isSwitch ? AlarmTypeEnum.交换机下线.getCode() : AlarmTypeEnum.服务器下线.getCode();
String alarmTypeMsg = isSwitch ? AlarmTypeEnum.交换机下线.getMsg() : AlarmTypeEnum.服务器下线.getMsg();
RmAlarmPushConfig rmAlarmPushConfig = new RmAlarmPushConfig();
rmAlarmPushConfig.setPushMethod(PushMethodEnum.企业微信.getCode());
rmAlarmPushConfig.setPushAlarmTypes(alarmTypeCode);
List<RmAlarmPushConfig> alarmConfigList = rmAlarmPushConfigService.selectRmAlarmPushConfigList(rmAlarmPushConfig);
RmAlarmLog updateData = new RmAlarmLog();
updateData.setId(rmAlarmLog.getId());
if (alarmConfigList != null && !alarmConfigList.isEmpty()) {
try {
Map<String, Object> alarmMap = new HashMap<>();
alarmMap.put("告警时间", rmAlarmLog.getAlarmTime());
alarmMap.put("IP", rmAlarmLog.getMgmPublicIp());
alarmMap.put("告警类型", alarmTypeMsg);
alarmMap.put("告警设备", rmAlarmLog.getClientId());
alarmMap.put("告警内容", rmAlarmLog.getAlarmContent());
alarmMap.put("业务名称", rmAlarmLog.getBusinessName());
for (RmAlarmPushConfig alarmPushConfig : alarmConfigList) {
String contentTemplate = alarmPushConfig.getMessageContent();
String webhookUrl = alarmPushConfig.getPushAddress();
if (alarmPushConfig.getContactPhones() != null) {
String[] phones = alarmPushConfig.getContactPhones().split(",");
WeChatWorkBot.sendTemplateMessage(webhookUrl, contentTemplate, alarmMap, rmAlarmLog.getAlarmContent(), phones, false);
} else {
WeChatWorkBot.sendTemplateMessage(webhookUrl, contentTemplate, alarmMap);
}
}
updateData.setPushFlag(1L);
} catch (Exception e){
updateData.setPushFlag(0L);
log.error("消息推送失败:{}", e.getMessage());
}
}else{
updateData.setPushFlag(2L);
}
rmAlarmLogService.updateRmAlarmLog(updateData);
rmAlarmLog.setAlarmType(alarmTypeCode);
sendAlarmPushUtil.sendAlarmPush(rmAlarmLog, alarmTypeMsg);
}
/**
@@ -3,6 +3,10 @@ package com.tongran.rocketmq.service.impl;
import com.tongran.common.core.utils.DateUtils;
import com.tongran.common.core.utils.EchartsDataUtils;
import com.tongran.rocketmq.domain.InitialCpuInfo;
import com.tongran.rocketmq.domain.RmAlarmLog;
import com.tongran.rocketmq.domain.RmAlarmThreshold;
import com.tongran.rocketmq.enums.AlarmTypeEnum;
import com.tongran.rocketmq.enums.ConditionItemEnum;
import com.tongran.rocketmq.mapper.InitialCpuInfoMapper;
import com.tongran.rocketmq.mapper.RmAlarmLogMapper;
import com.tongran.rocketmq.mapper.RmAlarmThresholdMapper;
@@ -14,6 +18,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -126,47 +131,47 @@ public class InitialCpuInfoServiceImpl implements IInitialCpuInfoService
public int batchInsertInitialCpuInfo(List<InitialCpuInfo> list) {
try {
// 查询告警阈值
// RmAlarmThreshold thresholdQuery = new RmAlarmThreshold();
// thresholdQuery.setAlarmType(AlarmTypeEnum.CPU使用率高.getCode());
// thresholdQuery.setConditionItem(ConditionItemEnum.服务器CPU使用率.getCode());
// List<RmAlarmThreshold> rmAlarmThresholdList = rmAlarmThresholdMapper.selectRmAlarmThresholdList(thresholdQuery);
// if(rmAlarmThresholdList != null && !rmAlarmThresholdList.isEmpty()){
// String operator = rmAlarmThresholdList.get(0).getCompareOperator();
// BigDecimal threshold = rmAlarmThresholdList.get(0).getThresholdValue();
// for (InitialCpuInfo initialCpuInfo : list) {
// BigDecimal cpuUti = new BigDecimal(initialCpuInfo.getUti());
// if(operator != null){
// // 根据运算符1大于,2小于,3等于 判断是否进行告警
// boolean shouldAlarm = false;
//
// // 根据运算符判断是否进行告警
// switch (operator) {
// case "1": // 大于
// shouldAlarm = cpuUti.compareTo(threshold) > 0;
// break;
// case "2": // 小于
// shouldAlarm = cpuUti.compareTo(threshold) < 0;
// break;
// case "3": // 等于
// shouldAlarm = cpuUti.compareTo(threshold) == 0;
// break;
// default:
// log.warn("未知的运算符: {}", operator);
// continue; // 跳过未知运算符的处理
// }
// if(shouldAlarm){
// RmAlarmLog rmAlarmLog = new RmAlarmLog();
// rmAlarmLog.setAlarmType(AlarmTypeEnum.CPU使用率高.getCode());
// rmAlarmLog.setClientId(initialCpuInfo.getClientId());
// rmAlarmLog.setAlarmTime(DateUtils.getNowDate());
// rmAlarmLog.setAlarmContent("服务器" + initialCpuInfo.getClientId() + "的CPU使用率高");
// rmAlarmLogMapper.insertRmAlarmLog(rmAlarmLog);
// // 推送消息
// sendAlarmPushUtil.sendAlarmPush(rmAlarmLog);
// }
// }
// }
// }
RmAlarmThreshold thresholdQuery = new RmAlarmThreshold();
thresholdQuery.setAlarmType(AlarmTypeEnum.CPU使用率高.getCode());
thresholdQuery.setConditionItem(ConditionItemEnum.服务器CPU使用率.getCode());
List<RmAlarmThreshold> rmAlarmThresholdList = rmAlarmThresholdMapper.selectRmAlarmThresholdList(thresholdQuery);
if(rmAlarmThresholdList != null && !rmAlarmThresholdList.isEmpty()){
String operator = rmAlarmThresholdList.get(0).getCompareOperator();
BigDecimal threshold = rmAlarmThresholdList.get(0).getThresholdValue();
for (InitialCpuInfo initialCpuInfo : list) {
BigDecimal cpuUti = new BigDecimal(initialCpuInfo.getUti());
if(operator != null){
// 根据运算符1大于,2小于,3等于 判断是否进行告警
boolean shouldAlarm = false;
// 根据运算符判断是否进行告警
switch (operator) {
case "1": // 大于
shouldAlarm = cpuUti.compareTo(threshold) > 0;
break;
case "2": // 小于
shouldAlarm = cpuUti.compareTo(threshold) < 0;
break;
case "3": // 等于
shouldAlarm = cpuUti.compareTo(threshold) == 0;
break;
default:
log.warn("未知的运算符: {}", operator);
continue; // 跳过未知运算符的处理
}
if(shouldAlarm){
RmAlarmLog rmAlarmLog = new RmAlarmLog();
rmAlarmLog.setAlarmType(AlarmTypeEnum.CPU使用率高.getCode());
rmAlarmLog.setClientId(initialCpuInfo.getClientId());
rmAlarmLog.setAlarmTime(DateUtils.getNowDate());
rmAlarmLog.setAlarmContent("服务器" + initialCpuInfo.getClientId() + "的CPU使用率高");
rmAlarmLogMapper.insertRmAlarmLog(rmAlarmLog);
// 推送消息
sendAlarmPushUtil.sendAlarmPush(rmAlarmLog, AlarmTypeEnum.CPU使用率高.getMsg());
}
}
}
}
return initialCpuInfoMapper.batchInsertInitialCpuInfo(list);
}catch (Exception e){
log.error("批量插入CPU信息失败,失败数量:{}", list.size(), e);
@@ -149,6 +149,14 @@ public class InitialMountPointInfoServiceImpl implements IInitialMountPointInfoS
List<InitialMountPointInfo> list = initialMountPointInfoMapper.selectInitialMountPointInfoList(initialMountPointInfo);
Map<String, Function<InitialMountPointInfo, ?>> extractors = new LinkedHashMap<>();
extractors.put("vfsUtilData", InitialMountPointInfo::getVfsUtil);
extractors.put("usedData", info -> {
Long total = info.getVfsTotal();
Long free = info.getVfsFree();
if (total == null || free == null) {
return UnitChangeUtil.convertUnitByValue(0L);
}
return UnitChangeUtil.convertUnitByValue(total - free);
});
return EchartsDataUtils.buildEchartsDataAutoPadding(list,InitialMountPointInfo::getCreateTime, extractors, initialMountPointInfo.getStartTime(), initialMountPointInfo.getEndTime());
}
@@ -3,7 +3,6 @@ package com.tongran.rocketmq.utils;
import com.tongran.rocketmq.domain.RmAlarmLog;
import com.tongran.rocketmq.domain.RmAlarmPushConfig;
import com.tongran.rocketmq.domain.RmNetworkInterface;
import com.tongran.rocketmq.enums.AlarmTypeEnum;
import com.tongran.rocketmq.enums.PushMethodEnum;
import com.tongran.rocketmq.service.IRmAlarmLogService;
import com.tongran.rocketmq.service.IRmAlarmPushConfigService;
@@ -33,7 +32,7 @@ public class SendAlarmPushUtil {
* 发送告警推送
* @param rmAlarmLog 告警日志参数
*/
public void sendAlarmPush(RmAlarmLog rmAlarmLog) {
public void sendAlarmPush(RmAlarmLog rmAlarmLog, String alarmTypeMsg) {
String clientId = rmAlarmLog.getClientId();
RmAlarmPushConfig rmAlarmPushConfig = new RmAlarmPushConfig();
@@ -59,7 +58,7 @@ public class SendAlarmPushUtil {
Map<String, Object> alarmMap = new HashMap<>();
alarmMap.put("告警时间", rmAlarmLog.getAlarmTime());
alarmMap.put("IP", rmAlarmLog.getMgmPublicIp());
alarmMap.put("告警类型", AlarmTypeEnum.CPU使用率高.getMsg());
alarmMap.put("告警类型", alarmTypeMsg);
alarmMap.put("告警设备", clientId.substring(clientId.length() - 8));
alarmMap.put("告警内容", rmAlarmLog.getAlarmContent());
for (RmAlarmPushConfig alarmPushConfig : alarmConfigList) {