diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/MonitorConstant.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/MonitorConstant.java new file mode 100644 index 00000000..40c11651 --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/MonitorConstant.java @@ -0,0 +1,45 @@ +package org.jeecg.common.constant; + +public interface MonitorConstant { + + //设备状态 1 正常 2 离线 3 告警 + String STATUS_ON = "1"; + String STATUS_OFF = "2"; + String STATUS_WARN = "3"; + + // 监控项名称 + String ITEM_CPUUSED = "cpuUtilization"; + String ITEM_SWAPUSED = "swapUtilization"; + String ITEM_MEMORYUSED = "memoryUtilization"; + String ITEM_RUNTIME = "uptime"; + String ITEM_RAMSIZE = "totalMemory"; + String ITEM_CPUCORES = "cpuNum"; + String ITEM_TOTALSIDKPAR = "diskNum"; + String ITEM_HOSTNAME = "hostName"; + String ITEM_OSVERSION = "osVersion"; + String ITEM_NETWORK = "netNum"; + String ITEM_LOCATION = "location"; + String ITEM_IP = "ip"; + String ITEM_ZONE = "timeZone"; + String ITEM_OSNAME = "osName"; + String ITEM_STARTTIME = "startTime"; + String ITEM_CPUTYPE = "cpuType"; + + + String PRIFIX_DISKUSED = "diskUsed"; + + + // 服务器类型 + String SERVER_APP = "SERVER-APP"; + String SERVER_DATABASE = "SERVER-DATABASE"; + + // 页面类型 + String PAGE_SUMMARY = "summary"; // 摘要 + String PAGE_PROCESS = "serviceAndProcess"; // 服务与进程 + String PAGE_CPU = "cpu"; // CPU + String PAGE_MEMORY = "memory"; // 内存 + String PAGE_DISK = "disk"; // 磁盘 + String PAGE_NET = "net"; // 网络 + String PAGE_EVENTLOG = "eventLog"; // 事件日志 + String PAGE_APPLOG = "appLog"; // 应用程序日志 +} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/NumUtil.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/NumUtil.java index 8d6554a8..2383e541 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/NumUtil.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/NumUtil.java @@ -63,4 +63,12 @@ public class NumUtil { return String.valueOf(decimal.setScale(scale, RoundingMode.HALF_UP) .doubleValue()); } + + public static String keepStr(String value, int scale){ + if (ObjectUtil.isNull(value)) + return null; + BigDecimal decimal = new BigDecimal(value); + return String.valueOf(decimal.setScale(scale, RoundingMode.HALF_UP) + .doubleValue()); + } } diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/BasicInfo.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/BasicInfo.java new file mode 100644 index 00000000..c80a7b57 --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/BasicInfo.java @@ -0,0 +1,47 @@ +package org.jeecg.modules.base.dto; + +import lombok.Data; +import lombok.experimental.Accessors; + +@Data +@Accessors(chain = true) +public class BasicInfo { + + private boolean runningState; + + private int alarmSms; + + private int alarmEmail; + + private int alarms; + + private String runTime; + + private String ramSize; + + private String cpuCores; + + private String totalDiskPar; + + private String hostName; + + private String osVersion; + + private String network; + + private String location; + + private String ip; + + private String zone; + + private String osName; + + private String startTime; + + private String cpuType; + + private double cpuUsed; + + private double memoryUsed; +} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/ServerDto.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/ServerDto.java index f9fac5f1..361566fc 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/ServerDto.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/ServerDto.java @@ -19,7 +19,7 @@ public class ServerDto implements Serializable { private String ipAddress; - private Integer alarms; + private int alarms; private boolean alarmRed; @@ -34,4 +34,10 @@ public class ServerDto implements Serializable { private String diskUsage; private boolean diskRed; + + public ServerDto() { + this.cpuUutilzation = "--"; + this.memoryUsage = "--"; + this.diskUsage = "--"; + } } diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/SourceItem.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/SourceItem.java new file mode 100644 index 00000000..981591ef --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/SourceItem.java @@ -0,0 +1,15 @@ +package org.jeecg.modules.base.dto; + +import lombok.Data; + +@Data +public class SourceItem { + + // 监控项Id + private String itemId; + + // 监控项名称 + private String name; + + private String sourceId; +} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/Host.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/Host.java index e3d75e17..5960061a 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/Host.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/Host.java @@ -16,8 +16,6 @@ public class Host implements Serializable { private String hostId; - private String status_dictText; - private Map items; private String status; diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/Item.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/Item.java index 0b4196f7..ac209a04 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/Item.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/Item.java @@ -18,4 +18,6 @@ public class Item { private String units; private String status; + + private String lastValue; // 监控项最新值 } 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 073b3b02..90b2dd54 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 @@ -1,6 +1,7 @@ package org.jeecg.modules.feignclient; import org.jeecg.common.api.vo.Result; +import org.jeecg.modules.base.entity.monitor.Host; import org.jeecg.modules.base.entity.monitor.ItemHistory; import org.jeecg.modules.base.entity.monitor.Servers; import org.springframework.cloud.openfeign.FeignClient; @@ -10,15 +11,21 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestParam; @Component -@FeignClient(name = "monitorAlarm",url = "http://123.124.245.134:7008/mobile/monitor") +@FeignClient(name = "monitorAlarm",url = "${monitor.url}") public interface MonitorAlarm { // --------------------后端专用------------------- - @GetMapping("list") - Result listBack(@RequestParam String code); + @GetMapping("list") // 获取指定服务器信息 + Result listBack(@RequestParam("code") String code); + + @GetMapping("list") // 获取所有在线服务器信息 + Result listOnApp(@RequestParam("status") String status, + @RequestParam("type") String type); + + @GetMapping("queryHostDetails") // 获取服务器摘要信息 + Result summary(@RequestParam("hostId") String hostId, + @RequestParam("pageName") String pageName); - @GetMapping("list") - Result listAllBack(); @GetMapping("queryItemHistory") Result itemBack(@RequestParam String itemId, diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/SysServerMapper.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/SysServerMapper.java index bbf10e90..0f8242ee 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/SysServerMapper.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/SysServerMapper.java @@ -3,6 +3,7 @@ package org.jeecg.modules.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.jeecg.modules.base.dto.IdCount; import org.jeecg.modules.base.dto.ServerDto; +import org.jeecg.modules.base.dto.SourceItem; import org.jeecg.modules.base.entity.postgre.SysServer; import org.jeecg.modules.entity.AlarmHistory; diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/ISysServerService.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/ISysServerService.java index dab233ba..5bb84a8f 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/ISysServerService.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/ISysServerService.java @@ -26,4 +26,6 @@ public interface ISysServerService extends IService { List listAll(); String getByName(String name); + + void details_BasicInfo(String sourceId); } 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 534dd334..4dfc5cb5 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 @@ -2,6 +2,8 @@ package org.jeecg.modules.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.convert.Convert; +import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; @@ -12,10 +14,14 @@ import org.apache.commons.lang3.StringUtils; 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.util.NumUtil; +import org.jeecg.modules.base.dto.BasicInfo; import org.jeecg.modules.base.dto.ServerDto; import org.jeecg.modules.base.dto.SourceDto; -import org.jeecg.modules.base.entity.monitor.Servers; +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.bizVo.SourceVo; import org.jeecg.modules.entity.AlarmHistory; @@ -26,9 +32,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import javax.naming.directory.ModificationItem; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.*; +import java.util.stream.Collectors; @Service("sysServerService") public class SysServerServiceImpl extends ServiceImpl implements ISysServerService { @@ -52,15 +60,33 @@ public class SysServerServiceImpl extends ServiceImpl serverDtos = baseMapper.findPage(params); - // 获取服务器信息列表 - Servers servers = monitorAlarm.listAllBack().getResult(); + // 获取所有在线服务器信息 + List hosts = monitorAlarm.listOnApp(MonitorConstant.STATUS_ON, + MonitorConstant.SERVER_APP).getResult().getRecords(); for (ServerDto serverDto : serverDtos) { + String name = serverDto.getName(); + int alarms = serverDto.getAlarms(); + serverDto.setAlarmRed(alarms > 0); + for (Host host : hosts) { + String code = host.getCode(); + if (!StrUtil.equals(name, code)) continue; - serverDto.setOnline(true) - .setServerInfo("(4-core (vCPU)16GiB)") - .setCpuUutilzation("35.8%").setMemoryUsage("55.8%") - .setDiskUsage("85.68%").setDiskRed(true); + Map items = host.getItems(); + // 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); + // 内存使用率 + 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("--"); + } } params.put("pageFlag","noPage"); // 统计Alarm总数 @@ -73,10 +99,6 @@ public class SysServerServiceImpl extends ServiceImpl findInfo(String id) { Result result = new Result(); @@ -197,4 +219,41 @@ public class SysServerServiceImpl extends ServiceImpl items = host.getItems(); + String upTime = items.get(MonitorConstant.ITEM_RUNTIME).getLastValue(); + String runTime = StrUtil.isBlank(upTime) ? "--" : + DateUtil.formatBetween(Long.parseLong(upTime) * 1000); + String ramSize = items.get(MonitorConstant.ITEM_RAMSIZE).getLastValue(); + String cpuCores = items.get(MonitorConstant.ITEM_CPUCORES).getLastValue(); + String totalDiskPar = items.get(MonitorConstant.ITEM_TOTALSIDKPAR).getLastValue(); + String hostName = items.get(MonitorConstant.ITEM_HOSTNAME).getLastValue(); + String osVersion = items.get(MonitorConstant.ITEM_OSVERSION).getLastValue(); + String netWork = items.get(MonitorConstant.ITEM_NETWORK).getLastValue(); + String location = items.get(MonitorConstant.ITEM_LOCATION).getLastValue(); + String ip = items.get(MonitorConstant.ITEM_IP).getLastValue(); + String zone = items.get(MonitorConstant.ITEM_ZONE).getLastValue(); + String osName = items.get(MonitorConstant.ITEM_OSNAME).getLastValue(); + String startTime = items.get(MonitorConstant.ITEM_STARTTIME).getLastValue(); + String cpuType = items.get(MonitorConstant.ITEM_CPUTYPE).getLastValue(); + + /* CPU MEMORY LOADS DISK */ + String cpuUsed = items.get(MonitorConstant.ITEM_CPUUSED).getLastValue(); // 0.24 + + String memoryUsed = items.get(MonitorConstant.ITEM_MEMORYUSED).getLastValue(); // 16.64927 + + Map diskUsedMap = items.entrySet().stream() // 6.540206 + .filter(entry -> entry.getKey().contains(MonitorConstant.PRIFIX_DISKUSED)) + .collect(Collectors.toMap(Map.Entry::getKey, item -> item.getValue().getLastValue())); + + BasicInfo basicInfo = new BasicInfo(); + } } diff --git a/jeecg-server-cloud/jeecg-system-cloud-start/src/main/resources/application.yml b/jeecg-server-cloud/jeecg-system-cloud-start/src/main/resources/application.yml index 1fe8ebd7..85003ada 100644 --- a/jeecg-server-cloud/jeecg-system-cloud-start/src/main/resources/application.yml +++ b/jeecg-server-cloud/jeecg-system-cloud-start/src/main/resources/application.yml @@ -16,8 +16,3 @@ spring: import: - optional:nacos:jeecg.yaml - optional:nacos:jeecg-@profile.name@.yaml -# 调用监控服务配置信息 -monitor: - username: wmhr - password: Wmhr.123 - url: http://123.124.245.134:7008/mobile/monitor \ No newline at end of file