feat:Server监控
This commit is contained in:
parent
51373c79d2
commit
37987f1bfa
|
@ -56,6 +56,13 @@ public class NumUtil {
|
|||
return decimal.setScale(scale, RoundingMode.HALF_UP).doubleValue();
|
||||
}
|
||||
|
||||
public static Double keep(String value, int scale){
|
||||
if (StrUtil.isBlank(value))
|
||||
return null;
|
||||
BigDecimal decimal = new BigDecimal(value);
|
||||
return decimal.setScale(scale, RoundingMode.HALF_UP).doubleValue();
|
||||
}
|
||||
|
||||
public static String keepStr(Double value, int scale){
|
||||
if (ObjectUtil.isNull(value))
|
||||
return null;
|
||||
|
@ -65,7 +72,7 @@ public class NumUtil {
|
|||
}
|
||||
|
||||
public static String keepStr(String value, int scale){
|
||||
if (ObjectUtil.isNull(value))
|
||||
if (StrUtil.isBlank(value))
|
||||
return null;
|
||||
BigDecimal decimal = new BigDecimal(value);
|
||||
return String.valueOf(decimal.setScale(scale, RoundingMode.HALF_UP)
|
||||
|
|
|
@ -3,6 +3,8 @@ package org.jeecg.modules.base.dto;
|
|||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class BasicInfo {
|
||||
|
@ -44,4 +46,6 @@ public class BasicInfo {
|
|||
private double cpuUsed;
|
||||
|
||||
private double memoryUsed;
|
||||
|
||||
private Map<String, Object> diskUsed;
|
||||
}
|
||||
|
|
|
@ -10,4 +10,8 @@ public class SourceDto implements Serializable {
|
|||
private String sourceId;
|
||||
|
||||
private String sourceName;
|
||||
|
||||
private String hostId;
|
||||
|
||||
private String cpuUsedItemId;
|
||||
}
|
||||
|
|
|
@ -39,6 +39,9 @@ public class SysServer implements Serializable {
|
|||
@TableField(value = "ip_address")
|
||||
private String ipAddress;
|
||||
|
||||
@TableField("host_id")
|
||||
private String hostId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.jeecg.modules.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.jeecg.common.api.QueryRequest;
|
||||
|
@ -63,4 +64,17 @@ public class SysServerController {
|
|||
List<SourceDto> sourceDtos = sysServerService.listAll();
|
||||
return Result.OK(sourceDtos);
|
||||
}
|
||||
|
||||
@GetMapping("sourcePage")
|
||||
@ApiOperation(value = "服务器服务名分页",notes = "服务器服务名分页")
|
||||
public Result sourcePage(QueryRequest query){
|
||||
Page<?> sourceDtos = sysServerService.pageAll(query);
|
||||
return Result.OK(sourceDtos);
|
||||
}
|
||||
|
||||
@GetMapping("detailsBasicInfo")
|
||||
@ApiOperation(value = "Server Monitor-Details-BasicInfo",notes = "Server Monitor-Details-BasicInfo")
|
||||
public Result<?> details_BasicInfo(@RequestParam String hostId){
|
||||
return sysServerService.details_BasicInfo(hostId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,29 +19,24 @@ public class SystemMonitorController {
|
|||
private MonitorAlarm monitorAlarm;
|
||||
|
||||
@GetMapping("list")
|
||||
@ApiOperation("")
|
||||
Result<?> list(@RequestParam String code,
|
||||
@RequestParam String hostId,
|
||||
@RequestParam Integer pageNo,
|
||||
@RequestParam Integer pageSize,
|
||||
@RequestParam String status,
|
||||
@RequestParam String type){
|
||||
@ApiOperation(value = "服务器列表详情信息", notes = "服务器列表详情信息")
|
||||
Result<?> list(String code, String hostId,
|
||||
Integer pageNo, Integer pageSize,
|
||||
String status, String type){
|
||||
return monitorAlarm.list(code, hostId, pageNo, pageSize, status, type);
|
||||
}
|
||||
|
||||
@GetMapping("queryHostDetails")
|
||||
@ApiOperation("")
|
||||
@ApiOperation(value = "单个服务器监控项信息", notes = "单个服务器监控项信息")
|
||||
Result<?> detail(@RequestParam String hostId,
|
||||
@RequestParam String pageName,
|
||||
@RequestParam Integer pageNo,
|
||||
@RequestParam Integer pageSize,
|
||||
@RequestParam String start,
|
||||
@RequestParam String end){
|
||||
Integer pageNo, Integer pageSize,
|
||||
String start, String end){
|
||||
return monitorAlarm.detail(hostId, pageName, pageNo, pageSize, start, end);
|
||||
}
|
||||
|
||||
@GetMapping("queryItemHistory")
|
||||
@ApiOperation("")
|
||||
@ApiOperation(value = "监控项历史数据信息", notes = "监控项历史数据信息")
|
||||
Result<?> item(@RequestParam String itemId,
|
||||
@RequestParam Integer itemType,
|
||||
@RequestParam String start,
|
||||
|
@ -50,7 +45,7 @@ public class SystemMonitorController {
|
|||
}
|
||||
|
||||
@GetMapping("queryItemHistoryData")
|
||||
@ApiOperation("")
|
||||
@ApiOperation(value = "监控项历史数据", notes = "监控项历史数据")
|
||||
Result<?> itemData(@RequestParam String itemId,
|
||||
@RequestParam Integer itemType,
|
||||
@RequestParam String start,
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package org.jeecg.modules.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.jeecg.modules.base.dto.IdCount;
|
||||
import org.jeecg.modules.base.dto.ServerDto;
|
||||
import org.jeecg.modules.base.dto.SourceDto;
|
||||
import org.jeecg.modules.base.dto.SourceItem;
|
||||
import org.jeecg.modules.base.entity.postgre.SysServer;
|
||||
import org.jeecg.modules.entity.AlarmHistory;
|
||||
|
@ -15,4 +17,9 @@ public interface SysServerMapper extends BaseMapper<SysServer> {
|
|||
List<AlarmHistory> findAlarmHistory(Map<String,Object> params);
|
||||
|
||||
List<ServerDto> findPage(Map<String,Object> params);
|
||||
|
||||
void saveOrUpdateHostId(@Param("hostId") String hostId,
|
||||
@Param("sourceId") String sourceId);
|
||||
|
||||
List<SourceDto> pageAll(String itemName);
|
||||
}
|
||||
|
|
|
@ -47,4 +47,20 @@
|
|||
LIMIT #{pageSize} OFFSET #{pageStart}
|
||||
</if>
|
||||
</select>
|
||||
<select id="pageAll" resultType="org.jeecg.modules.base.dto.SourceDto">
|
||||
SELECT
|
||||
s.ID AS sourceId,
|
||||
s.NAME AS sourceName,
|
||||
s.host_id AS hostId,
|
||||
i.id AS cpuUsedItemId
|
||||
FROM
|
||||
sys_server s
|
||||
LEFT JOIN alarm_item i ON s.ID = i.source_id AND i.NAME = #{itemName}
|
||||
ORDER BY
|
||||
s.status DESC,
|
||||
s.NAME ASC
|
||||
</select>
|
||||
<update id="saveOrUpdateHostId" parameterType="String">
|
||||
UPDATE sys_server SET host_id = #{hostId} WHERE id = #{sourceId}
|
||||
</update>
|
||||
</mapper>
|
|
@ -1,5 +1,6 @@
|
|||
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;
|
||||
|
@ -25,7 +26,11 @@ public interface ISysServerService extends IService<SysServer> {
|
|||
|
||||
List<SourceDto> listAll();
|
||||
|
||||
Page<?> pageAll(QueryRequest query);
|
||||
|
||||
String getByName(String name);
|
||||
|
||||
void details_BasicInfo(String sourceId);
|
||||
Result<?> details_BasicInfo(String hostId);
|
||||
|
||||
void saveOrUpdateHostId(String sourceId, String hostId);
|
||||
}
|
||||
|
|
|
@ -57,10 +57,12 @@ public class AlarmItemServiceImpl extends ServiceImpl<AlarmItemMapper, AlarmItem
|
|||
Result<Servers> result = monitorAlarm.listBack(code);
|
||||
List<Host> hosts = result.getResult().getRecords();
|
||||
List<Item> items = new ArrayList<>();
|
||||
String hostId = null;
|
||||
for (Host host : hosts) {
|
||||
boolean equals = host.getCode().equals(code);
|
||||
if(!equals) continue;
|
||||
items = ListUtil.toList(host.getItems().values());
|
||||
hostId = host.getHostId();
|
||||
}
|
||||
if (CollUtil.isEmpty(items))
|
||||
return false;
|
||||
|
@ -72,6 +74,7 @@ public class AlarmItemServiceImpl extends ServiceImpl<AlarmItemMapper, AlarmItem
|
|||
alarmItem.setSourceId(sourceId);
|
||||
alarmItems.add(alarmItem);
|
||||
}
|
||||
serverService.saveOrUpdateHostId(sourceId, hostId);
|
||||
return saveOrUpdateBatch(alarmItems);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -17,6 +17,7 @@ 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.common.util.PageUtil;
|
||||
import org.jeecg.modules.base.dto.BasicInfo;
|
||||
import org.jeecg.modules.base.dto.ServerDto;
|
||||
import org.jeecg.modules.base.dto.SourceDto;
|
||||
|
@ -211,6 +212,19 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
|
|||
return sourceDtos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<?> pageAll(QueryRequest query) {
|
||||
Integer pageNo = query.getPageNo();
|
||||
Integer pageSize = query.getPageSize();
|
||||
List<SourceDto> sourceDtos = baseMapper.pageAll(MonitorConstant.ITEM_CPUUSED);
|
||||
|
||||
int total = sourceDtos.size();
|
||||
Page<SourceDto> page = new Page<>(pageNo, pageSize, total);
|
||||
List<SourceDto> records = PageUtil.page(pageNo, pageSize, sourceDtos);
|
||||
page.setRecords(records);
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getByName(String name) {
|
||||
LambdaQueryWrapper<SysServer> wrapper = new LambdaQueryWrapper<>();
|
||||
|
@ -221,18 +235,23 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
|
|||
}
|
||||
|
||||
@Override
|
||||
public void details_BasicInfo(String sourceId) {
|
||||
Host host = monitorAlarm.summary(null, MonitorConstant.PAGE_SUMMARY)
|
||||
.getResult();
|
||||
public Result<?> details_BasicInfo(String hostId) {
|
||||
if (StrUtil.isBlank(hostId))
|
||||
return Result.error("HostId" + Prompt.PARAM_REQUIRED);
|
||||
Host host = monitorAlarm.summary(hostId, MonitorConstant.PAGE_SUMMARY).getResult();
|
||||
/* BasicInfo */
|
||||
if (ObjectUtil.isNull(host))
|
||||
return Result.error("The Host To Be Queried Does Not Exist!");
|
||||
// 服务器是否在线
|
||||
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);
|
||||
upTime = StrUtil.isBlank(upTime) ? "--" :
|
||||
NumUtil.keepStr(Long.parseLong(upTime) / 3600.0, 1) + "h";
|
||||
String ramSize = items.get(MonitorConstant.ITEM_RAMSIZE).getLastValue();
|
||||
ramSize = StrUtil.isBlank(ramSize) ? "--" :
|
||||
NumUtil.keepStr(Double.parseDouble(ramSize.replace("MB", "")) / 1024, 1) + "GB";
|
||||
String cpuCores = items.get(MonitorConstant.ITEM_CPUCORES).getLastValue();
|
||||
String totalDiskPar = items.get(MonitorConstant.ITEM_TOTALSIDKPAR).getLastValue();
|
||||
String hostName = items.get(MonitorConstant.ITEM_HOSTNAME).getLastValue();
|
||||
|
@ -247,13 +266,35 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
|
|||
|
||||
/* CPU MEMORY LOADS DISK */
|
||||
String cpuUsed = items.get(MonitorConstant.ITEM_CPUUSED).getLastValue(); // 0.24
|
||||
|
||||
Double cpuUsedValue = NumUtil.keep(cpuUsed, 3);
|
||||
cpuUsedValue = ObjectUtil.isNull(cpuUsedValue) ? 0 : cpuUsedValue * 100;
|
||||
String memoryUsed = items.get(MonitorConstant.ITEM_MEMORYUSED).getLastValue(); // 16.64927
|
||||
|
||||
Double memoryUsedValue = NumUtil.keep(memoryUsed, 1);
|
||||
memoryUsedValue = ObjectUtil.isNull(memoryUsedValue) ? 0 : memoryUsedValue;
|
||||
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()));
|
||||
Map<String, Object> diskUsedValue = new HashMap<>();
|
||||
List<String> xData = new ArrayList<>();
|
||||
List<Double> yData = new ArrayList<>();
|
||||
diskUsedMap.forEach((key, value) -> {
|
||||
Double v = NumUtil.keep(value, 1);
|
||||
xData.add(StrUtil.split(key, StrUtil.C_SLASH).get(1));
|
||||
yData.add(ObjectUtil.isNotNull(v) ? v : 0);
|
||||
});
|
||||
diskUsedValue.put("xData", xData);diskUsedValue.put("yData", yData);
|
||||
|
||||
BasicInfo basicInfo = new BasicInfo();
|
||||
basicInfo.setRunningState(online).setRunTime(upTime).setRamSize(ramSize)
|
||||
.setCpuCores(cpuCores).setTotalDiskPar(totalDiskPar).setHostName(hostName)
|
||||
.setOsVersion(osVersion).setNetwork(netWork).setLocation(location).setIp(ip)
|
||||
.setZone(zone).setOsName(osName).setStartTime(startTime).setCpuType(cpuType)
|
||||
.setCpuUsed(cpuUsedValue).setMemoryUsed(memoryUsedValue).setDiskUsed(diskUsedValue);
|
||||
return Result.OK(basicInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveOrUpdateHostId(String sourceId, String hostId) {
|
||||
baseMapper.saveOrUpdateHostId(hostId, sourceId);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user