feat:Server监控
This commit is contained in:
parent
751c5d8cf2
commit
f53f8e4dca
|
@ -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"; // 应用程序日志
|
||||||
|
}
|
|
@ -63,4 +63,12 @@ public class NumUtil {
|
||||||
return String.valueOf(decimal.setScale(scale, RoundingMode.HALF_UP)
|
return String.valueOf(decimal.setScale(scale, RoundingMode.HALF_UP)
|
||||||
.doubleValue());
|
.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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -19,7 +19,7 @@ public class ServerDto implements Serializable {
|
||||||
|
|
||||||
private String ipAddress;
|
private String ipAddress;
|
||||||
|
|
||||||
private Integer alarms;
|
private int alarms;
|
||||||
|
|
||||||
private boolean alarmRed;
|
private boolean alarmRed;
|
||||||
|
|
||||||
|
@ -34,4 +34,10 @@ public class ServerDto implements Serializable {
|
||||||
private String diskUsage;
|
private String diskUsage;
|
||||||
|
|
||||||
private boolean diskRed;
|
private boolean diskRed;
|
||||||
|
|
||||||
|
public ServerDto() {
|
||||||
|
this.cpuUutilzation = "--";
|
||||||
|
this.memoryUsage = "--";
|
||||||
|
this.diskUsage = "--";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -16,8 +16,6 @@ public class Host implements Serializable {
|
||||||
|
|
||||||
private String hostId;
|
private String hostId;
|
||||||
|
|
||||||
private String status_dictText;
|
|
||||||
|
|
||||||
private Map<String,Item> items;
|
private Map<String,Item> items;
|
||||||
|
|
||||||
private String status;
|
private String status;
|
||||||
|
|
|
@ -18,4 +18,6 @@ public class Item {
|
||||||
private String units;
|
private String units;
|
||||||
|
|
||||||
private String status;
|
private String status;
|
||||||
|
|
||||||
|
private String lastValue; // 监控项最新值
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.jeecg.modules.feignclient;
|
package org.jeecg.modules.feignclient;
|
||||||
|
|
||||||
import org.jeecg.common.api.vo.Result;
|
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.ItemHistory;
|
||||||
import org.jeecg.modules.base.entity.monitor.Servers;
|
import org.jeecg.modules.base.entity.monitor.Servers;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
@ -10,15 +11,21 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@FeignClient(name = "monitorAlarm",url = "http://123.124.245.134:7008/mobile/monitor")
|
@FeignClient(name = "monitorAlarm",url = "${monitor.url}")
|
||||||
public interface MonitorAlarm {
|
public interface MonitorAlarm {
|
||||||
|
|
||||||
// --------------------后端专用-------------------
|
// --------------------后端专用-------------------
|
||||||
@GetMapping("list")
|
@GetMapping("list") // 获取指定服务器信息
|
||||||
Result<Servers> listBack(@RequestParam String code);
|
Result<Servers> listBack(@RequestParam("code") String code);
|
||||||
|
|
||||||
|
@GetMapping("list") // 获取所有在线服务器信息
|
||||||
|
Result<Servers> listOnApp(@RequestParam("status") String status,
|
||||||
|
@RequestParam("type") String type);
|
||||||
|
|
||||||
|
@GetMapping("queryHostDetails") // 获取服务器摘要信息
|
||||||
|
Result<Host> summary(@RequestParam("hostId") String hostId,
|
||||||
|
@RequestParam("pageName") String pageName);
|
||||||
|
|
||||||
@GetMapping("list")
|
|
||||||
Result<Servers> listAllBack();
|
|
||||||
|
|
||||||
@GetMapping("queryItemHistory")
|
@GetMapping("queryItemHistory")
|
||||||
Result<ItemHistory> itemBack(@RequestParam String itemId,
|
Result<ItemHistory> itemBack(@RequestParam String itemId,
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.jeecg.modules.mapper;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import org.jeecg.modules.base.dto.IdCount;
|
import org.jeecg.modules.base.dto.IdCount;
|
||||||
import org.jeecg.modules.base.dto.ServerDto;
|
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.base.entity.postgre.SysServer;
|
||||||
import org.jeecg.modules.entity.AlarmHistory;
|
import org.jeecg.modules.entity.AlarmHistory;
|
||||||
|
|
||||||
|
|
|
@ -26,4 +26,6 @@ public interface ISysServerService extends IService<SysServer> {
|
||||||
List<SourceDto> listAll();
|
List<SourceDto> listAll();
|
||||||
|
|
||||||
String getByName(String name);
|
String getByName(String name);
|
||||||
|
|
||||||
|
void details_BasicInfo(String sourceId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@ package org.jeecg.modules.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
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.NumberUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
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.QueryRequest;
|
||||||
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.api.vo.Result;
|
||||||
import org.jeecg.common.constant.DateConstant;
|
import org.jeecg.common.constant.DateConstant;
|
||||||
|
import org.jeecg.common.constant.MonitorConstant;
|
||||||
import org.jeecg.common.constant.Prompt;
|
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.ServerDto;
|
||||||
import org.jeecg.modules.base.dto.SourceDto;
|
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.entity.postgre.SysServer;
|
||||||
import org.jeecg.modules.base.bizVo.SourceVo;
|
import org.jeecg.modules.base.bizVo.SourceVo;
|
||||||
import org.jeecg.modules.entity.AlarmHistory;
|
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.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.naming.directory.ModificationItem;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service("sysServerService")
|
@Service("sysServerService")
|
||||||
public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer> implements ISysServerService {
|
public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer> implements ISysServerService {
|
||||||
|
@ -52,15 +60,33 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
|
||||||
params.put("startDate",startDate);
|
params.put("startDate",startDate);
|
||||||
params.put("endDate",endDate);
|
params.put("endDate",endDate);
|
||||||
List<ServerDto> serverDtos = baseMapper.findPage(params);
|
List<ServerDto> serverDtos = baseMapper.findPage(params);
|
||||||
// 获取服务器信息列表
|
// 获取所有在线服务器信息
|
||||||
Servers servers = monitorAlarm.listAllBack().getResult();
|
List<Host> hosts = monitorAlarm.listOnApp(MonitorConstant.STATUS_ON,
|
||||||
|
MonitorConstant.SERVER_APP).getResult().getRecords();
|
||||||
for (ServerDto serverDto : serverDtos) {
|
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)
|
Map<String, Item> items = host.getItems();
|
||||||
.setServerInfo("(4-core (vCPU)16GiB)")
|
// cpu利用率
|
||||||
.setCpuUutilzation("35.8%").setMemoryUsage("55.8%")
|
Item cpuItem = items.getOrDefault(MonitorConstant.ITEM_CPUUSED, new Item());
|
||||||
.setDiskUsage("85.68%").setDiskRed(true);
|
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");
|
params.put("pageFlag","noPage");
|
||||||
// 统计Alarm总数
|
// 统计Alarm总数
|
||||||
|
@ -73,10 +99,6 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
|
||||||
return Result.OK(page);
|
return Result.OK(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
System.out.println(NumberUtil.formatPercent(0.2367, 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<?> findInfo(String id) {
|
public Result<?> findInfo(String id) {
|
||||||
Result result = new Result();
|
Result result = new Result();
|
||||||
|
@ -197,4 +219,41 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
|
||||||
.orElse(new SysServer()).getId();
|
.orElse(new SysServer()).getId();
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void details_BasicInfo(String sourceId) {
|
||||||
|
Host host = monitorAlarm.summary(null, MonitorConstant.PAGE_SUMMARY)
|
||||||
|
.getResult();
|
||||||
|
/* BasicInfo */
|
||||||
|
// 服务器是否在线
|
||||||
|
String status = host.getStatus();
|
||||||
|
boolean online = StrUtil.equals(status, MonitorConstant.STATUS_ON);
|
||||||
|
Map<String, Item> 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<String, String> 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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,3 @@ spring:
|
||||||
import:
|
import:
|
||||||
- optional:nacos:jeecg.yaml
|
- optional:nacos:jeecg.yaml
|
||||||
- optional:nacos:jeecg-@profile.name@.yaml
|
- optional:nacos:jeecg-@profile.name@.yaml
|
||||||
# 调用监控服务配置信息
|
|
||||||
monitor:
|
|
||||||
username: wmhr
|
|
||||||
password: Wmhr.123
|
|
||||||
url: http://123.124.245.134:7008/mobile/monitor
|
|
Loading…
Reference in New Issue
Block a user