feat:Server监控

This commit is contained in:
nieziyan 2023-09-21 20:49:31 +08:00
parent 699a8b068b
commit f984421fc1
6 changed files with 64 additions and 7 deletions

View File

@ -0,0 +1,11 @@
package org.jeecg.modules.base.dto;
import lombok.Data;
@Data
public class IdCount {
private String id;
private Integer count;
}

View File

@ -0,0 +1,24 @@
package org.jeecg.modules.base.entity.monitor;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import java.io.Serializable;
/**
* 返回的是List集合
*/
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class ItemHistoryData implements Serializable {
private String date;
private String itemId;
private Long ns;
private Long clock;
private Double value;
}

View File

@ -17,6 +17,9 @@ public interface MonitorAlarm {
@GetMapping("list")
Result<Servers> listBack(@RequestParam String code);
@GetMapping("list")
Result<Servers> listAllBack();
@GetMapping("queryItemHistory")
Result<ItemHistory> itemBack(@RequestParam String itemId,
@RequestParam Integer itemType,

View File

@ -1,6 +1,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.entity.postgre.SysServer;
import org.jeecg.modules.entity.AlarmHistory;

View File

@ -42,10 +42,9 @@
LEFT JOIN alarm_rule r ON s.ID = r.source_id
LEFT JOIN alarm_log l ON r.ID = l.rule_id
AND l.alarm_start_date BETWEEN #{startDate} AND #{endDate}
GROUP BY s.ID,s.NAME,s.ip_address
GROUP BY s.ID, s.NAME, s.ip_address
<if test="pageFlag == null">
LIMIT #{pageSize} OFFSET #{pageStart}
</if>
</select>
</mapper>

View File

@ -2,6 +2,7 @@ package org.jeecg.modules.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@ -14,11 +15,14 @@ import org.jeecg.common.constant.DateConstant;
import org.jeecg.common.constant.Prompt;
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.postgre.SysServer;
import org.jeecg.modules.base.bizVo.SourceVo;
import org.jeecg.modules.entity.AlarmHistory;
import org.jeecg.modules.feignclient.MonitorAlarm;
import org.jeecg.modules.mapper.SysServerMapper;
import org.jeecg.modules.service.ISysServerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -29,8 +33,11 @@ import java.util.*;
@Service("sysServerService")
public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer> implements ISysServerService {
@Autowired
private MonitorAlarm monitorAlarm;
@Override
public Result findPage(QueryRequest query) {
public Result<?> findPage(QueryRequest query) {
Integer pageNo = query.getPageNo();
Integer pageSize = query.getPageSize();
Integer pageStart = (pageNo - 1) * pageSize;
@ -45,21 +52,33 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
params.put("startDate",startDate);
params.put("endDate",endDate);
List<ServerDto> serverDtos = baseMapper.findPage(params);
// 获取服务器信息列表
Servers servers = monitorAlarm.listAllBack().getResult();
for (ServerDto serverDto : serverDtos) {
serverDto.setOnline(true)
.setServerInfo("(4-core (vCPU)16GiB)")
.setCpuUutilzation("35.8%").setMemoryUsage("55.8%")
.setDiskUsage("85.68%").setDiskRed(true);
}
params.put("pageFlag","noPage");
long total = baseMapper.findPage(params).size();
// 统计Alarm总数
List<ServerDto> noPage = baseMapper.findPage(params);
int alarms = noPage.stream().mapToInt(ServerDto::getAlarms).sum();
// 获取记录总条数
long total = noPage.size();
Page<ServerDto> page = new Page<>(pageNo, pageSize, total);
page.setRecords(serverDtos);
return Result.OK(page);
}
public static void main(String[] args) {
System.out.println(NumberUtil.formatPercent(0.2367, 1));
}
@Override
public Result findInfo(String id) {
public Result<?> findInfo(String id) {
Result result = new Result();
if (StringUtils.isBlank(id)){
result.error500("id信息不能为空");
@ -85,11 +104,11 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
LambdaQueryWrapper<SysServer> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(SysServer::getName,name);
if (CollUtil.isNotEmpty(list(wrapper)))
return Result.error("Name"+Prompt.NOT_REPEAT);
return Result.error("Name" + Prompt.NOT_REPEAT);
wrapper.clear();
wrapper.eq(SysServer::getIpAddress,ipAddress);
if (CollUtil.isNotEmpty(list(wrapper)))
return Result.error("IP Address"+Prompt.NOT_REPEAT);
return Result.error("IP Address" + Prompt.NOT_REPEAT);
int count = baseMapper.insert(sysServer);
if (count == 1)