perf: 优化运维心跳,增加告警

dev
huangfeng 10 months ago
parent 80643a81b7
commit 7197fb4900

@ -3,7 +3,11 @@ package com.shxy.xymanager_admin.controller;
import com.shxy.xymanager_common.base.BaseController; import com.shxy.xymanager_common.base.BaseController;
import com.shxy.xymanager_common.base.ResponseReult; import com.shxy.xymanager_common.base.ResponseReult;
import com.shxy.xymanager_common.exception.ApiException;
import com.shxy.xymanager_common.util.DingTalkPushUtil;
import com.shxy.xymanager_common.util.HttpRequestUtil; 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_service.service.MntnService; import com.shxy.xymanager_service.service.MntnService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@ -26,13 +30,27 @@ public class MntnController extends BaseController {
@PostMapping("") @PostMapping("")
@ApiOperation("上传心跳并返回命令") @ApiOperation("上传心跳并返回命令")
public HashMap<String, Object> sync(@RequestBody HashMap<String, Object> data, public HashMap<String, Object> sync(@RequestBody String data,
HttpServletRequest req, HttpServletResponse resp) throws Exception { HttpServletRequest req, HttpServletResponse resp) {
try {
String ip = HttpRequestUtil.getRemoteIp(req); String ip = HttpRequestUtil.getRemoteIp(req);
String multi = req.getHeader("Accept-Cmds"); String multi = req.getHeader("Accept-Cmds");
HashMap<String, Object> result = service.sync(ip, multi, data); HashMap<String, Object> map = JSONUtil.json2Object(data, HashMap.class);
String cmdid = (String) map.get("id");
if (StringUtils.isBlank(cmdid)) {
throw new ApiException("id不能为空");
}
HashMap<String, Object> result = service.sync(cmdid, ip, multi, data);
resp.setHeader("ResSyncTime", String.valueOf(System.currentTimeMillis())); resp.setHeader("ResSyncTime", String.valueOf(System.currentTimeMillis()));
return result; return result;
} catch (Exception ex) {
String str = ex.getMessage() + ", 数据:" + data;
DingTalkPushUtil.pushText("运维心跳", str);
HashMap<String, Object> result = new HashMap<>();
result.put("code", "400");
result.put("msg", ex.getMessage());
return result;
}
} }
@GetMapping("status") @GetMapping("status")

@ -851,11 +851,10 @@ public class CmdServiceImpl implements CmdService {
@Async @Async
@Override @Override
public void addRawReport(Integer termId, String ip, HashMap<String, Object> data) { public void addRawReport(Integer termId, String ip, String content) {
String json = JSONUtil.object2Json(data);
MntnRawReports item = new MntnRawReports(); MntnRawReports item = new MntnRawReports();
item.setTermId(termId); item.setTermId(termId);
item.setContent(json); item.setContent(content);
item.setIp(ip); item.setIp(ip);
item.setCreateTime(System.currentTimeMillis() / 1000); item.setCreateTime(System.currentTimeMillis() / 1000);
rawReportsMapper.insert(item); rawReportsMapper.insert(item);

@ -38,8 +38,7 @@ public class MntnServiceImpl implements MntnService {
CmdService cmdService; CmdService cmdService;
@Override @Override
public HashMap<String, Object> sync(String ip, String multi, HashMap<String, Object> data) throws Exception { public HashMap<String, Object> sync(String cmdid, String ip, String multi, String data) throws Exception {
String cmdid = (String) data.get("id");
Terminals term = terminalExtService.getByCmdid(cmdid); Terminals term = terminalExtService.getByCmdid(cmdid);
if (term == null) { if (term == null) {
throw new ApiException("该装置不存在"); throw new ApiException("该装置不存在");

@ -6,8 +6,6 @@ import com.shxy.xymanager_common.entity.MntnCmdHistory;
import com.shxy.xymanager_common.entity.MntnCmds; import com.shxy.xymanager_common.entity.MntnCmds;
import com.shxy.xymanager_common.model.CmdModel; import com.shxy.xymanager_common.model.CmdModel;
import java.util.HashMap;
public interface CmdService { public interface CmdService {
@ -19,5 +17,5 @@ public interface CmdService {
void send(CmdModel model) throws Exception; void send(CmdModel model) throws Exception;
void addRawReport(Integer termId, String ip, HashMap<String, Object> data); void addRawReport(Integer termId, String ip, String content);
} }

@ -4,7 +4,7 @@ import java.util.HashMap;
public interface MntnService { public interface MntnService {
HashMap<String, Object> sync(String ip, String multi, HashMap<String, Object> data) throws Exception; HashMap<String, Object> sync(String cmdid, String ip, String multi, String data) throws Exception;
void result(Integer cid, Integer res, String content); void result(Integer cid, Integer res, String content);
} }

Loading…
Cancel
Save