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..7eda8513 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,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Map; import static org.jeecg.modules.base.enums.Qiye.IS; @@ -140,11 +142,10 @@ public class StatusAspect { // 更新该服务器的HostId 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); 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..430b251c 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, 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()));