perf: 优化运维心跳告警

dev
huangfeng 10 months ago
parent 85218039ae
commit 517df2d7a7

@ -8,6 +8,7 @@ import com.shxy.xymanager_common.util.DingTalkPushUtil;
import com.shxy.xymanager_common.util.HttpRequestUtil;
import com.shxy.xymanager_common.util.JSONUtil;
import com.shxy.xymanager_common.util.StringUtils;
import com.shxy.xymanager_framework.timeTask.ClearCacheTask;
import com.shxy.xymanager_service.service.MntnService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -45,9 +46,12 @@ public class MntnController extends BaseController {
resp.setHeader("ResSyncTime", String.valueOf(System.currentTimeMillis()));
return result;
} catch (Exception ex) {
log.error("上传心跳异常", ex);
String str = ex.getMessage() + ", ip=" + ip + ", url=" + url + ", " + data;
DingTalkPushUtil.pushText("运维心跳", str);
if (!ClearCacheTask.heartbeatMap.containsKey(ip)) {
ClearCacheTask.heartbeatMap.put(ip, 1L);
log.error("上传心跳异常", ex);
String str = ex.getMessage() + ", ip=" + ip + ", url=" + url + ", " + data;
DingTalkPushUtil.pushText("运维心跳", str);
}
HashMap<String, Object> result = new HashMap<>();
result.put("code", "400");
result.put("msg", ex.getMessage());

@ -1,7 +1,6 @@
package com.shxy.xymanager_framework.timeTask;
import com.shxy.xymanager_common.util.DingTalkPushUtil;
import com.shxy.xymanager_common.zhiping.PulliceModel;
import com.shxy.xymanager_framework.socket.WebSocketServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
@ -25,11 +24,6 @@ public class AlertTask {
shutdown = 1;
}
@Scheduled(cron = "0 0 9 * * ?")
private void clear() {
PulliceModel.fubinDoneMap.clear();
}
@Scheduled(initialDelay = 60000, fixedDelay = 2000)
private void sendYWMsg() {
if (shutdown == 0 && DingTalkPushUtil.alertYW.size() > 0) {

@ -1,19 +1,36 @@
package com.shxy.xymanager_framework.timeTask;
import com.shxy.xymanager_common.zhiping.PulliceModel;
import com.shxy.xymanager_service.service.NewCacheService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
@Service
public class ClearCacheTask {
public static HashMap<Integer, Long> warnMap = new HashMap<>();
public static HashMap<String, Long> heartbeatMap = new HashMap<>();
@Resource
NewCacheService newCacheService;
@Scheduled(cron = "0 0 3 * * ?")
private void clear() {
private void clearOneDayStat() {
newCacheService.clearOneDayStat();
}
@Scheduled(cron = "0 0 9,13 * * MON-FRI")
private void clearWarnMap() {
warnMap.clear();
heartbeatMap.clear();
}
@Scheduled(cron = "0 0 9 * * ?")
private void clearFubin() {
PulliceModel.fubinDoneMap.clear();
}
}

@ -28,8 +28,8 @@ public class MntnCheckTask {
private int maxCount = 50;
private int maxDay = 3;
private int lostPer = 10;
private HashMap<Integer, Long> warnMap = new HashMap<>();
private HashMap<Integer, Long> lostMap = new HashMap<>();
public HashMap<Integer, Long> lostingMap = new HashMap<>();
private HashMap<Integer, Long> _lostMap;
@Value("${maintain.check}")
private boolean needCheck;
@ -50,16 +50,11 @@ public class MntnCheckTask {
shutdown = 1;
}
@Scheduled(cron = "0 0 9,13 * * MON-FRI")
private void clear() {
warnMap.clear();
}
@Scheduled(initialDelay = 60000, fixedDelay = 60 * 5 * 1000)
private void checkAll() {
if (needCheck) {
try {
lostMap.clear();
_lostMap = new HashMap<>();
log.info("MntnCheckTask.checkAll 开始.");
Map<Integer, Terminals> terminalMap = newCacheService.getTerminalMap();
Iterator<Integer> it = terminalMap.keySet().iterator();
@ -72,7 +67,7 @@ public class MntnCheckTask {
for (MntnActivities activity : activityList) {
int lostCount = 0;
for (Terminals term : activity.getTerms()) {
if (lostMap.containsKey(term.getId())) {
if (_lostMap.containsKey(term.getId())) {
lostCount++;
}
}
@ -84,6 +79,7 @@ public class MntnCheckTask {
this.sendWarningLost(activity, lostCount);
}
}
lostingMap = _lostMap;
log.info("MntnCheckTask.checkAll 结束.");
} catch (Exception e) {
log.error("MntnCheckTask.checkAll error.", e);
@ -116,7 +112,7 @@ public class MntnCheckTask {
Long lasttime = list.get(0).getCreateTime();
long days = (System.currentTimeMillis() / 1000 - lasttime) / 60 / 60 / 24;
if (days >= maxDay) {
lostMap.put(termId, days);
_lostMap.put(termId, days);
}
}
}
@ -127,12 +123,12 @@ public class MntnCheckTask {
String str = "装置" + term.getCmdid() + "最近" + minutes + "分钟内,运维报送次数:" + count
+ "次, 超过设定的阈值" + maxCount + "次;";
if (warnMap.containsKey(term.getId())) {
Long cnt = warnMap.get(term.getId());
if (ClearCacheTask.warnMap.containsKey(term.getId())) {
Long cnt = ClearCacheTask.warnMap.get(term.getId());
cnt++;
warnMap.put(term.getId(), cnt);
ClearCacheTask.warnMap.put(term.getId(), cnt);
} else {
warnMap.put(term.getId(), 1L);
ClearCacheTask.warnMap.put(term.getId(), 1L);
log.warn(str);
DingTalkPushUtil.alertYW.add(str);
}
@ -143,8 +139,8 @@ public class MntnCheckTask {
+ lostCount + "台,超过设定的阈值" + lostPer + "%;";
int id = activity.getId() - 100000;
if (!warnMap.containsKey(id)) {
warnMap.put(id, 1L);
if (!ClearCacheTask.warnMap.containsKey(id)) {
ClearCacheTask.warnMap.put(id, 1L);
log.warn(str);
DingTalkPushUtil.alertYW.add(str);
}

Loading…
Cancel
Save