diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/TokenContext.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/TokenContext.java new file mode 100644 index 00000000..195f59af --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/TokenContext.java @@ -0,0 +1,19 @@ +package org.jeecg.common; + +import org.jeecg.common.util.RedisUtil; +import org.jeecg.common.util.SpringContextUtils; +import org.jeecg.common.util.TokenUtils; + +public class TokenContext implements AutoCloseable{ + + private final ThreadLocal userToken = new ThreadLocal<>(); + + public void setToken() { + userToken.set(TokenUtils.threadToken()); + } + + @Override + public void close() throws Exception { + userToken.remove(); + } +} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/RedisConstant.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/RedisConstant.java index 59f9ba4f..da9979ac 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/RedisConstant.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/RedisConstant.java @@ -35,7 +35,9 @@ public interface RedisConstant { String EMAIL_SENDER = "Email_Sender"; - String MANAGE_TOKEN = "Manage:Token"; // 运管系统Token + String MANAGE_TOKEN = "Token:Manage"; // 运管系统Token - String QIYE_EMAIL_TOKEN = "QiyeEmail:Token"; // 网易企业邮箱Token + String QIYE_EMAIL_TOKEN = "Token:QiyeEmail"; // 网易企业邮箱Token + + String THREAD_TOKEN = "Token:Thread"; // 线程中设置Token 定时任务中使用Feign调用接口使用 否则提示401 } diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/enums/SampleType.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/enums/SampleType.java new file mode 100644 index 00000000..a162f620 --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/enums/SampleType.java @@ -0,0 +1,25 @@ +package org.jeecg.common.constant.enums; + +import cn.hutool.core.util.StrUtil; +import lombok.AllArgsConstructor; +import lombok.Getter; +/* +* 谱文件类型 +* */ +@Getter +@AllArgsConstructor +public enum SampleType { + BETA("B", "Beta"), GAMMA("G", "Gamma"); + + private final String value; + + private final String type; + + public static SampleType typeOf(String type){ + for (SampleType sampleType : SampleType.values()) { + if (StrUtil.equals(type, sampleType.getType())) + return sampleType; + } + return null; + } +} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/TokenUtils.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/TokenUtils.java index 22c68dc4..79067605 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/TokenUtils.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/TokenUtils.java @@ -5,6 +5,7 @@ import org.apache.commons.lang3.StringUtils; import org.jeecg.common.api.CommonAPI; import org.jeecg.common.constant.CacheConstant; import org.jeecg.common.constant.CommonConstant; +import org.jeecg.common.constant.RedisConstant; import org.jeecg.common.constant.TenantConstant; import org.jeecg.common.desensitization.util.SensitiveInfoUtil; import org.jeecg.common.exception.JeecgBoot401Exception; @@ -164,7 +165,21 @@ public class TokenUtils { // 模拟登录生成Token String token = JwtUtil.sign(username, secret); // 设置Token缓存有效时间为 5 分钟 - redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token, 3 * 60); + redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token, 5 * 60); + return token; + } + + public static String threadToken() { + RedisUtil redisUtil = SpringContextUtils.getBean(RedisUtil.class); + if (redisUtil.hasKey(RedisConstant.THREAD_TOKEN)) + return (String) redisUtil.get(RedisConstant.THREAD_TOKEN); + + String username = CommonConstant.TEMP_TOKEN_USERNAME; + String secret = CommonConstant.TEMP_TOKEN_SECRET; + // 模拟登录生成Token + String token = JwtUtil.sign(username, secret); + // 设置Token缓存有效时间为 5 分钟 + redisUtil.set(RedisConstant.THREAD_TOKEN, token, 5 * 60); return token; } } diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/History.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/History.java new file mode 100644 index 00000000..eb0aed02 --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/History.java @@ -0,0 +1,14 @@ +package org.jeecg.modules.base.entity.monitor; + +import lombok.Data; +import java.io.Serializable; + +@Data +public class History implements Serializable { + + private String name; + + private Long date; + + private Double value; +} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/ItemHistory.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/ItemHistory.java index 359b7bdd..3bafb3d6 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/ItemHistory.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/ItemHistory.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import lombok.Data; import java.io.Serializable; +import java.util.List; @Data @JsonIgnoreProperties(ignoreUnknown = true) @@ -20,4 +21,6 @@ public class ItemHistory implements Serializable { private String name; private String units; + + private List list; } diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/postgre/AlarmAnalysisLog.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/postgre/AlarmAnalysisLog.java index c7b29164..f91c0e94 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/postgre/AlarmAnalysisLog.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/postgre/AlarmAnalysisLog.java @@ -16,6 +16,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; import com.fasterxml.jackson.annotation.JsonFormat; +import org.jeecg.common.system.base.entity.JeecgEntity; import org.jeecg.modules.base.dto.NuclideInfo; import org.springframework.format.annotation.DateTimeFormat; import org.jeecgframework.poi.excel.annotation.Excel; @@ -24,11 +25,8 @@ import org.jeecgframework.poi.excel.annotation.Excel; @TableName("alarm_analysis_log") @EqualsAndHashCode(callSuper = false) @Accessors(chain = true) -public class AlarmAnalysisLog implements Serializable{ - - @TableId(type = IdType.ASSIGN_ID) - private String id; - +public class AlarmAnalysisLog extends JeecgEntity implements Serializable{ + private String ruleId; private String stationId; @@ -51,6 +49,10 @@ public class AlarmAnalysisLog implements Serializable{ private String sampleName; + private String sampleType; + + private String analyst; + @TableField(exist = false) private List nuclideInfoList; } diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/postgre/SysDatabase.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/postgre/SysDatabase.java index 33cba269..c1be21bc 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/postgre/SysDatabase.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/postgre/SysDatabase.java @@ -28,6 +28,9 @@ public class SysDatabase implements Serializable { @TableField(value = "name") private String name; + @TableField(value = "host_id") + private String hostId; + /** * 用户名称 */ diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/Demo.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/Demo.java deleted file mode 100644 index 939a2b28..00000000 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/Demo.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.jeecg.modules; - -import cn.hutool.core.collection.ListUtil; -import cn.hutool.core.io.FileUtil; -import cn.hutool.core.util.ArrayUtil; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.jeecg.common.email.EmailServiceManager; -import org.jeecg.modules.base.entity.postgre.SysEmail; - -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.*; - -public class Demo { - - public static void main(String[] args) { - Executor executor = Executors.newFixedThreadPool(3); - for (int i = 0; i < 3; i++) { - CompletableFuture.runAsync(Demo::test2, executor); - } - } - - public static void test(){ - SysEmail email1 = new SysEmail(); - email1.setEmailServerAddress("imap.qiye.163.com"); - email1.setUsername("cnndc.rn.ng@ndc.org.cn"); - email1.setPassword("cnndc66367220"); - email1.setPort(993); - - /*SysEmail email2 = new SysEmail(); - email2.setEmailServerAddress("imap.qiye.163.com"); - email2.setUsername("cnndc.rn.ng@ndc.org.cn"); - email2.setPassword("cnndc66367220"); - email2.setPort(993);*/ - - SysEmail email2 = new SysEmail(); - email2.setEmailServerAddress("imap.exmail.qq.com"); - email2.setUsername("xiaoguangbin@hivekion.com"); - email2.setPassword("Ans9sLY4kVnux7ai"); - email2.setPort(143); - - List list = ListUtil.toList(email1, email2); - - List> futures = new ArrayList<>(); - Executor executor = Executors.newFixedThreadPool(5); - EmailServiceManager manager = EmailServiceManager.getInstance(); - for (SysEmail email : list) { - manager.init(email); - CompletableFuture.supplyAsync(manager::canReceive, executor) - .thenAccept(status -> FileUtil.writeUtf8Lines(ListUtil.toList(status), "C:\\Users\\a\\Desktop\\"+ email.getUsername() + ".txt")); - } - /*CompletableFuture allFutures = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])); - - try { - allFutures.get(); // 等待所有任务完成 - } catch (InterruptedException | ExecutionException e) { - e.printStackTrace(); - }*/ - } - - public static void test2(){ - throw new RuntimeException("测试异常"); - } -} diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/aspect/StatusAspect.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/aspect/StatusAspect.java index 4854cfdc..f8e86077 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/aspect/StatusAspect.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/aspect/StatusAspect.java @@ -2,6 +2,7 @@ package org.jeecg.modules.aspect; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; @@ -44,6 +45,8 @@ import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; import static org.jeecg.modules.base.enums.Qiye.IS; @@ -94,7 +97,30 @@ public class StatusAspect { Object[] args = point.getArgs(); if (ArrayUtil.length(args) == 0) return; SysDatabase database = (SysDatabase) args[0]; - databaseService.status2Redis(database); + try { + databaseService.status2Redis(database); + String token = ManageUtil.getToken(); + Page hostPage = monitorAlarm.dbList(null, 1, 99, token).getResult(); + if (ObjectUtil.isNull(hostPage) || CollUtil.isEmpty(hostPage.getRecords())) + return; + List hosts = hostPage.getRecords(); + String name = database.getName(); + Host host = null; + for (Host oneHost : hosts) { + if (StrUtil.equals(name, oneHost.getCode())) + host = oneHost; + } + if (ObjectUtil.isNull(host)) + return; + // 更新数据源的HostId + database.setHostId(host.getHostId()); + databaseService.updateById(database); + }catch (FeignException.Unauthorized e){ + ManageUtil.refreshToken(); + log.warn("向运管系统查询Hosts信息异常: Token失效,已刷新Token"); + }catch (Exception e){ + log.error("数据源更新状态/绑定HostId异常: {}", e.getMessage()); + } } /* @@ -124,27 +150,24 @@ public class StatusAspect { List hosts = hostPage.getRecords(); Host host = null; for (Host oneHost : hosts) { - String code = oneHost.getCode(); - if (StrUtil.equals(ipAddress, code)) + if (StrUtil.equals(ipAddress, oneHost.getCode())) host = oneHost; } if (ObjectUtil.isNull(host)){ redisUtil.hset(key, id, new NameValue(name, status)); return; } - status = host.getStatus(); - String hostId = host.getHostId(); - server.setHostId(hostId); // 更新该服务器状态信息 + status = host.getStatus(); redisUtil.hset(key, id, new NameValue(name, status)); // 更新该服务器的HostId + server.setHostId(host.getHostId()); serverService.updateById(server); // 同步服务器监控项 - Page itemPage = monitorAlarm.allItems(hostId, - MonitorConstant.pageNo, MonitorConstant.pageSize, token).getResult(); - if (ObjectUtil.isNull(itemPage) || CollUtil.isEmpty(itemPage.getRecords())) + Map itemMap = host.getItems(); + if (MapUtil.isEmpty(itemMap) || CollUtil.isEmpty(itemMap.values())) return; - List items = itemPage.getRecords(); + Collection items = itemMap.values(); List alarmItems = new ArrayList<>(); items.forEach(item -> { AlarmItem alarmItem = BeanUtil.copyProperties(item, AlarmItem.class); @@ -156,7 +179,7 @@ public class StatusAspect { ManageUtil.refreshToken(); log.warn("向运管系统查询Hosts信息异常: Token失效,已刷新Token"); }catch (Exception e){ - log.error("向运管系统查询Hosts信息异常: {}", e.getMessage()); + log.error("服务器更新状态/绑定HostId/绑定监控项异常: {}", e.getMessage()); } } @@ -184,8 +207,8 @@ public class StatusAspect { @AfterReturning("execution(* org.jeecg.modules.service.impl.SysEmailServiceImpl.deleteById(..)) || " + "execution(* org.jeecg.modules.service.impl.SysDatabaseServiceImpl.deleteById(..))") public void deleteRules(JoinPoint point){ - Object[] args = point.getArgs(); // 删除数据库和邮箱相关联的报警规则 + Object[] args = point.getArgs(); if (ArrayUtil.length(args) > 0) alarmRuleService.deleteBySourceId((String) args[0]); } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/AlarmItemController.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/AlarmItemController.java index 4a31bf15..1ed9e715 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/AlarmItemController.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/AlarmItemController.java @@ -21,12 +21,6 @@ import java.util.stream.Collectors; @RequestMapping("alarmItem") public class AlarmItemController extends JeecgController { - @GetMapping("syncServerItem") - @ApiOperation(value = "同步服务器监控项信息",notes = "同步服务器监控项信息") - public boolean syncServerItem(){ - return service.syncServerItem(); - } - @GetMapping("alarmItems") @ApiOperation(value = "服务器所有监控项",notes = "服务器所有监控项") public Result alarmItems(@RequestParam String sourceId){ diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/SysDatabaseController.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/SysDatabaseController.java index 1d28d228..a56b70a4 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/SysDatabaseController.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/SysDatabaseController.java @@ -23,43 +23,43 @@ public class SysDatabaseController { @GetMapping("findPage") @ApiOperation(value = "分页查询数据库配置信息", notes = "分页查询数据库配置信息") - public Result findPage(QueryRequest query){ + public Result findPage(QueryRequest query){ return sysDatabaseService.findPage(query); } @GetMapping("findInfo") @ApiOperation(value = "查询数据库配置信息详情", notes = "查询数据库配置信息详情") - public Result findInfo(String id){ + public Result findInfo(String id){ return sysDatabaseService.findInfo(id); } @PostMapping("create") @ApiOperation(value = "新增数据库配置信息", notes = "新增数据库配置信息") - public Result create(@RequestBody SysDatabase sysDatabase){ + public Result create(@RequestBody SysDatabase sysDatabase){ return sysDatabaseService.create(sysDatabase); } @PutMapping("update") @ApiOperation(value = "修改数据库配置信息", notes = "修改数据库配置信息") - public Result update(@RequestBody SysDatabase sysDatabase){ + public Result update(@RequestBody SysDatabase sysDatabase){ return sysDatabaseService.update(sysDatabase); } @DeleteMapping("deleteById") @ApiOperation(value = "删除数据库配置信息", notes = "删除数据库配置信息") - public Result deleteById(String id){ + public Result deleteById(String id){ return sysDatabaseService.deleteById(id); } @GetMapping("findAlarmHistory") @ApiOperation(value = "查询数据库历史报警信息", notes = "查询数据库历史报警信息") - public Result findAlarmHistory(SourceVo sourceVo){ + public Result findAlarmHistory(SourceVo sourceVo){ return sysDatabaseService.findAlarmHistory(sourceVo); } @GetMapping("sourceList") @ApiOperation(value = "数据库服务名列表",notes = "数据库服务名列表") - public Result sourceList(){ + public Result sourceList(){ List sourceDtos = sysDatabaseService.listAll(); return Result.OK(sourceDtos); } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/SystemMonitorController.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/SystemMonitorController.java index 0dbfa44d..20f64be2 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/SystemMonitorController.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/SystemMonitorController.java @@ -5,6 +5,7 @@ import io.swagger.annotations.ApiOperation; import org.jeecg.common.api.vo.Result; import org.jeecg.modules.feignclient.ManageUtil; import org.jeecg.modules.feignclient.MonitorAlarm; +import org.jeecg.modules.service.IMonitorService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -19,9 +20,12 @@ public class SystemMonitorController { @Autowired private MonitorAlarm monitorAlarm; + @Autowired + private IMonitorService monitorService; + @GetMapping("list") @ApiOperation(value = "服务器列表详情信息", notes = "服务器列表详情信息") - Result list(String code, String hostId, + public Result list(String code, String hostId, Integer pageNo, Integer pageSize, String status, String type){ String token = ManageUtil.getToken(); @@ -30,31 +34,41 @@ public class SystemMonitorController { @GetMapping("queryHostDetails") @ApiOperation(value = "单个服务器监控项信息", notes = "单个服务器监控项信息") - Result detail(@RequestParam String hostId, - @RequestParam String pageName, - Integer pageNo, Integer pageSize, - String start, String end){ + public Result detail(@RequestParam String hostId, + @RequestParam String pageName, + Integer pageNo, Integer pageSize, + String start, String end){ String token = ManageUtil.getToken(); return monitorAlarm.detail(hostId, pageName, pageNo, pageSize, start, end, token); } @GetMapping("queryItemHistory") @ApiOperation(value = "监控项历史数据信息", notes = "监控项历史数据信息") - Result item(@RequestParam String itemId, - @RequestParam Integer itemType, - @RequestParam String start, - @RequestParam String end){ + public Result item(@RequestParam String itemId, + @RequestParam Integer itemType, + @RequestParam String start, + @RequestParam String end){ String token = ManageUtil.getToken(); return monitorAlarm.item(itemId, itemType, start, end, token); } @GetMapping("queryItemHistoryData") @ApiOperation(value = "监控项历史数据", notes = "监控项历史数据") - Result itemData(@RequestParam String itemId, - @RequestParam Integer itemType, - @RequestParam String start, - @RequestParam String end){ + public Result itemData(@RequestParam String itemId, + @RequestParam Integer itemType, + @RequestParam String start, + @RequestParam String end){ String token = ManageUtil.getToken(); return monitorAlarm.itemData(itemId, itemType, start, end, token); } + + /* ---------------------- 数据库相关接口 ---------------------- */ + @GetMapping("dbDetail") + @ApiOperation(value = "数据库指标信息", notes = "数据库指标信息") + public Result dbDetail(@RequestParam("hostId") String hostId, + @RequestParam("start") String start, + @RequestParam("end") String end){ + String token = ManageUtil.getToken(); + return monitorAlarm.dbDetail(hostId, start, end, token); + } } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/feignclient/ManageUtil.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/feignclient/ManageUtil.java index f7499eef..8296fe56 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/feignclient/ManageUtil.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/feignclient/ManageUtil.java @@ -39,6 +39,7 @@ public class ManageUtil { LoginVo loginVo = new LoginVo(username, password); Result loginRes = monitorAlarm.login(loginVo); String token = loginRes.getResult().getToken(); + // 有效期为 12h redisUtil.set(RedisConstant.MANAGE_TOKEN, token, JwtUtil.EXPIRE_TIME / 1000 - 10); return token; } @@ -47,6 +48,7 @@ public class ManageUtil { LoginVo loginVo = new LoginVo(username, password); Result loginRes = monitorAlarm.login(loginVo); String token = loginRes.getResult().getToken(); + // 有效期为 12h redisUtil.set(RedisConstant.MANAGE_TOKEN, token, JwtUtil.EXPIRE_TIME / 1000 - 10); } } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/feignclient/MonitorAlarm.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/feignclient/MonitorAlarm.java index c01fa34c..3fea1903 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/feignclient/MonitorAlarm.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/feignclient/MonitorAlarm.java @@ -43,12 +43,6 @@ public interface MonitorAlarm { @RequestParam("pageSize") Integer pageSize, @RequestHeader("X-Access-Token") String token); - @GetMapping("/omms/device/monitor/queryAllItems") - Result> allItems(@RequestParam("hostId") String hostId, - @RequestParam("pageNo") Integer pageNo, - @RequestParam("pageSize") Integer pageSize, - @RequestHeader("X-Access-Token") String token); - @GetMapping("/omms/device/monitor/queryHostDetails") // 获取服务器摘要信息 Result summary(@RequestParam("hostId") String hostId, @RequestParam("pageName") String pageName, @@ -116,9 +110,14 @@ public interface MonitorAlarm { // -------------------------------------------数据库相关----------------------------------------------------- @GetMapping("/omms/monitor/db/item/detail") - Result dbDetail(@RequestParam("hostId") String hostId, - @RequestHeader("X-Access-Token") String token); + Result> dbDetail(@RequestParam("hostId") String hostId, + @RequestParam("start") String start, + @RequestParam("end") String end, + @RequestHeader("X-Access-Token") String token); @GetMapping("/omms/monitor/db/list") - Result dbList(@RequestHeader("X-Access-Token") String token); + Result> dbList(@RequestParam("code") String code, + @RequestParam("pageNo") Integer pageNo, + @RequestParam("pageSize") Integer pageSize, + @RequestHeader("X-Access-Token") String token); } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/redisStream/AnalysisConsumer.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/redisStream/AnalysisConsumer.java index 60ea3c64..eae4faa6 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/redisStream/AnalysisConsumer.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/redisStream/AnalysisConsumer.java @@ -14,6 +14,7 @@ import lombok.extern.slf4j.Slf4j; import org.jeecg.common.config.mqtoken.UserTokenContext; import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.constant.SymbolConstant; +import org.jeecg.common.constant.enums.SampleType; import org.jeecg.common.util.RedisStreamUtil; import org.jeecg.common.util.SpringContextUtils; import org.jeecg.modules.base.dto.NuclideInfo; @@ -186,6 +187,9 @@ public class AnalysisConsumer implements StreamListener { - boolean syncServerItem(); void deleteByHostId(String serverId); diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/IMonitorService.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/IMonitorService.java new file mode 100644 index 00000000..6998ccbc --- /dev/null +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/IMonitorService.java @@ -0,0 +1,16 @@ +package org.jeecg.modules.service; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; +import org.jeecg.common.api.QueryRequest; +import org.jeecg.common.api.vo.Result; +import org.jeecg.modules.base.bizVo.SourceVo; +import org.jeecg.modules.base.dto.SourceDto; +import org.jeecg.modules.base.entity.postgre.SysServer; + +import java.util.List; + +public interface IMonitorService{ + + void dbDetails(String start, String end, String hostId); +} diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmItemServiceImpl.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmItemServiceImpl.java index 39eb4905..a23b14d2 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmItemServiceImpl.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmItemServiceImpl.java @@ -45,46 +45,9 @@ import static org.jeecg.modules.base.enums.SourceType.SERVER; @Slf4j public class AlarmItemServiceImpl extends ServiceImpl implements IAlarmItemService { - @Autowired - private MonitorAlarm monitorAlarm; - - @Autowired - private ISysServerService serverService; - @Autowired private IAlarmItemDeService alarmItemDeService; - @Transactional - public boolean syncServerItem() { - try { - // 获取所有监控服务器信息(不包括数据库服务) - String token = ManageUtil.getToken(); - List hosts = monitorAlarm.listApp(MonitorConstant.SERVER_APP, - MonitorConstant.pageNo, MonitorConstant.pageSize, token).getResult().getRecords(); - // 获取所有服务器信息 - List servers = serverService.list(); - List hostIds = servers.stream().map(SysServer::getHostId).filter(StrUtil::isNotBlank) - .collect(Collectors.toList()); - // 收集监控服务器列表中当前系统录入的服务器 并将收集所有监控项 - List items = hosts.stream().filter(host -> CollUtil.contains(hostIds, host.getHostId())) - .flatMap(host -> host.getItems().values().stream()) - .collect(Collectors.toList()); - List alarmItems = new ArrayList<>(); - for (Item item : items) { - AlarmItem alarmItem = BeanUtil.copyProperties(item, AlarmItem.class); - alarmItem.setId(item.getItemId()); - alarmItems.add(alarmItem); - } - return saveOrUpdateBatch(alarmItems); - }catch (FeignException.Unauthorized e){ - ManageUtil.refreshToken(); - log.warn("向运管系统同步Server监控项信息异常: Token失效,已刷新Token"); - return false; - } catch (Exception e){ - log.error("向运管系统同步Server监控项信息异常: {}", e.getMessage()); - return false; - } - } @Override public void deleteByHostId(String hostId) { diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/MonitorServiceImpl.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/MonitorServiceImpl.java new file mode 100644 index 00000000..e1453b76 --- /dev/null +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/MonitorServiceImpl.java @@ -0,0 +1,54 @@ +package org.jeecg.modules.service.impl; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.map.MapUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import feign.FeignException; +import lombok.extern.slf4j.Slf4j; +import org.jeecg.common.api.QueryRequest; +import org.jeecg.common.api.vo.Result; +import org.jeecg.common.constant.DateConstant; +import org.jeecg.common.constant.MonitorConstant; +import org.jeecg.common.constant.Prompt; +import org.jeecg.common.constant.RedisConstant; +import org.jeecg.common.util.NumUtil; +import org.jeecg.common.util.RedisUtil; +import org.jeecg.modules.base.bizVo.SourceVo; +import org.jeecg.modules.base.dto.*; +import org.jeecg.modules.base.entity.monitor.Host; +import org.jeecg.modules.base.entity.monitor.Item; +import org.jeecg.modules.base.entity.postgre.SysServer; +import org.jeecg.modules.base.enums.ServerStatus; +import org.jeecg.modules.entity.AlarmHistory; +import org.jeecg.modules.feignclient.ManageUtil; +import org.jeecg.modules.feignclient.MonitorAlarm; +import org.jeecg.modules.mapper.SysServerMapper; +import org.jeecg.modules.service.IMonitorService; +import org.jeecg.modules.service.ISysServerService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +@Service +public class MonitorServiceImpl implements IMonitorService { + + @Autowired + private MonitorAlarm monitorAlarm; + + @Override + public void dbDetails(String start, String end, String hostId) { + + } +} diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysDatabaseServiceImpl.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysDatabaseServiceImpl.java index 00cd5524..0027344c 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysDatabaseServiceImpl.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysDatabaseServiceImpl.java @@ -86,7 +86,7 @@ public class SysDatabaseServiceImpl extends ServiceImpl sourceDtos = new ArrayList<>(); for (SysDatabase sysDatabase : list(wrapper)) { SourceDto sourceDto = new SourceDto(); + sourceDto.setHostId(sysDatabase.getHostId()); sourceDto.setSourceId(sysDatabase.getId()); sourceDto.setSourceName(sysDatabase.getName()); sourceDtos.add(sourceDto); diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysServerServiceImpl.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysServerServiceImpl.java index 595cae7d..643918b5 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysServerServiceImpl.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysServerServiceImpl.java @@ -109,17 +109,19 @@ public class SysServerServiceImpl extends ServiceImpl items = host.getItems(); - // cpu利用率 + // CPU利用率 Item cpuItem = items.getOrDefault(MonitorConstant.ITEM_CPUUSED, new Item()); String cpuValue = cpuItem.getLastValue(); String cpu = StrUtil.isBlank(cpuValue) ? "--" : - NumberUtil.formatPercent(Double.parseDouble(cpuValue), 1); + NumUtil.keepStr(cpuValue, 1) + "%"; // 内存使用率 Item memoryItem = items.getOrDefault(MonitorConstant.ITEM_MEMORYUSED, new Item()); String memoryValue = memoryItem.getLastValue(); String memory = StrUtil.isBlank(memoryValue) ? "--" : NumUtil.keepStr(memoryValue, 1) + "%"; // 磁盘使用率 + + serverDto.setOnline(true).setCpuUutilzation(cpu) .setMemoryUsage(memory).setDiskUsage("--"); } @@ -309,17 +311,19 @@ public class SysServerServiceImpl extends ServiceImpl diskUsedMap = items.entrySet().stream() // 6.540206 .filter(entry -> entry.getKey().contains(MonitorConstant.PRIFIX_DISKUSED)) .collect(Collectors.toMap(Map.Entry::getKey, item -> item.getValue().getLastValue())); diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/feignclient/AbnormalAlarmClient.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/feignclient/AbnormalAlarmClient.java index a1cdf22d..bac9b1b7 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/feignclient/AbnormalAlarmClient.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/feignclient/AbnormalAlarmClient.java @@ -37,10 +37,6 @@ public interface AbnormalAlarmClient { @GetMapping("/nuclideParam/refresh") boolean refreshParam(); - /* AlarmItemController下相关接口 */ - @GetMapping("/alarmItem/syncServerItem") - boolean syncServerItem(); - /* SysDatabaseController下相关接口 */ @GetMapping("/sysDatabase/getNameById") String getDatabaseName(@RequestParam String id); diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/NuclideParamJob.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/NuclideParamJob.java index 745267ae..e298a420 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/NuclideParamJob.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/NuclideParamJob.java @@ -1,6 +1,7 @@ package org.jeecg.modules.quartz.job; import lombok.extern.slf4j.Slf4j; +import org.jeecg.common.TokenContext; import org.jeecg.common.config.mqtoken.UserTokenContext; import org.jeecg.common.util.SpringContextUtils; import org.jeecg.modules.feignclient.AbnormalAlarmClient; @@ -21,28 +22,14 @@ import static org.jeecg.common.util.TokenUtils.getTempToken; @PersistJobDataAfterExecution public class NuclideParamJob implements Job { - private AbnormalAlarmClient alarmClient; - @Override public void execute(JobExecutionContext context) throws JobExecutionException { - try { - init(); + try (TokenContext tokenContext = new TokenContext()){ + tokenContext.setToken(); + AbnormalAlarmClient alarmClient = SpringContextUtils.getBean(AbnormalAlarmClient.class); alarmClient.refreshParam(); }catch (Exception e){ - e.printStackTrace(); - }finally { - destroy(); + log.error("定时任务[NuclideParamJob]执行异常: {}", e.getMessage()); } } - - private void init(){ - // start:生成临时Token到线程中 - UserTokenContext.setToken(getTempToken()); - alarmClient = SpringContextUtils.getBean(AbnormalAlarmClient.class); - } - - private void destroy(){ - // end:删除临时Token - UserTokenContext.remove(); - } } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/NucliedAvgJob.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/NucliedAvgJob.java index 6b561cf2..0382fb8f 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/NucliedAvgJob.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/NucliedAvgJob.java @@ -1,6 +1,7 @@ package org.jeecg.modules.quartz.job; import lombok.extern.slf4j.Slf4j; +import org.jeecg.common.TokenContext; import org.jeecg.common.config.mqtoken.UserTokenContext; import org.jeecg.common.constant.DateConstant; import org.jeecg.common.util.SpringContextUtils; @@ -25,32 +26,18 @@ import static org.jeecg.common.util.TokenUtils.getTempToken; @PersistJobDataAfterExecution public class NucliedAvgJob implements Job { - private AbnormalAlarmClient alarmClient; - @Override public void execute(JobExecutionContext context) throws JobExecutionException { - try { - init(); + try (TokenContext tokenContext = new TokenContext()){ + tokenContext.setToken(); + AbnormalAlarmClient alarmClient = SpringContextUtils.getBean(AbnormalAlarmClient.class); alarmClient.calculateConc(); log.info(log()); }catch (Exception e){ - e.printStackTrace(); - }finally { - destroy(); + log.error("定时任务[NucliedAvgJob]执行异常: {}", e.getMessage()); } } - private void init(){ - // start:生成临时Token到线程中 - UserTokenContext.setToken(getTempToken()); - alarmClient = SpringContextUtils.getBean(AbnormalAlarmClient.class); - } - - private void destroy(){ - // end:删除临时Token - UserTokenContext.remove(); - } - private String log(){ String now = LocalDateTime.now() .format(DateTimeFormatter.ofPattern(DateConstant.DATE_TIME)); diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/SyncServerItemJob.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/SyncServerItemJob.java deleted file mode 100644 index 01f5819e..00000000 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/SyncServerItemJob.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.jeecg.modules.quartz.job; - -import org.jeecg.common.config.mqtoken.UserTokenContext; -import org.jeecg.common.util.SpringContextUtils; -import org.jeecg.modules.feignclient.AbnormalAlarmClient; -import org.quartz.*; - -import static org.jeecg.common.util.TokenUtils.getTempToken; - -/** - * 此处的同步是指:当定时任务的执行时间大于任务的时间 - * 间隔时会等待第一个任务执行完成才会走第二个任务 - */ -@DisallowConcurrentExecution -@PersistJobDataAfterExecution -public class SyncServerItemJob implements Job { - - private AbnormalAlarmClient alarmClient; - - @Override - public void execute(JobExecutionContext context) throws JobExecutionException { - try { - init(); - alarmClient.syncServerItem(); - }catch (Exception e){ - e.printStackTrace(); - }finally { - destroy(); - } - } - - private void init(){ - // start:生成临时Token到线程中 - UserTokenContext.setToken(getTempToken()); - alarmClient = SpringContextUtils.getBean(AbnormalAlarmClient.class); - } - - private void destroy(){ - // end:删除临时Token - UserTokenContext.remove(); - } -}