Merge remote-tracking branch 'origin/mdc' into mdc

This commit is contained in:
qiaoqinzheng 2023-12-28 09:36:48 +08:00
commit da660a667b
26 changed files with 266 additions and 249 deletions

View File

@ -0,0 +1,19 @@
package org.jeecg.common;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.common.util.TokenUtils;
public class TokenContext implements AutoCloseable{
private final ThreadLocal<String> userToken = new ThreadLocal<>();
public void setToken() {
userToken.set(TokenUtils.threadToken());
}
@Override
public void close() throws Exception {
userToken.remove();
}
}

View File

@ -35,7 +35,9 @@ public interface RedisConstant {
String EMAIL_SENDER = "Email_Sender";
String MANAGE_TOKEN = "Manage:Token"; // 运管系统Token
String MANAGE_TOKEN = "Token:Manage"; // 运管系统Token
String QIYE_EMAIL_TOKEN = "QiyeEmail:Token"; // 网易企业邮箱Token
String QIYE_EMAIL_TOKEN = "Token:QiyeEmail"; // 网易企业邮箱Token
String THREAD_TOKEN = "Token:Thread"; // 线程中设置Token 定时任务中使用Feign调用接口使用 否则提示401
}

View File

@ -0,0 +1,25 @@
package org.jeecg.common.constant.enums;
import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
/*
* 谱文件类型
* */
@Getter
@AllArgsConstructor
public enum SampleType {
BETA("B", "Beta"), GAMMA("G", "Gamma");
private final String value;
private final String type;
public static SampleType typeOf(String type){
for (SampleType sampleType : SampleType.values()) {
if (StrUtil.equals(type, sampleType.getType()))
return sampleType;
}
return null;
}
}

View File

@ -5,6 +5,7 @@ import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.api.CommonAPI;
import org.jeecg.common.constant.CacheConstant;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.RedisConstant;
import org.jeecg.common.constant.TenantConstant;
import org.jeecg.common.desensitization.util.SensitiveInfoUtil;
import org.jeecg.common.exception.JeecgBoot401Exception;
@ -164,7 +165,21 @@ public class TokenUtils {
// 模拟登录生成Token
String token = JwtUtil.sign(username, secret);
// 设置Token缓存有效时间为 5 分钟
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token, 3 * 60);
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token, 5 * 60);
return token;
}
public static String threadToken() {
RedisUtil redisUtil = SpringContextUtils.getBean(RedisUtil.class);
if (redisUtil.hasKey(RedisConstant.THREAD_TOKEN))
return (String) redisUtil.get(RedisConstant.THREAD_TOKEN);
String username = CommonConstant.TEMP_TOKEN_USERNAME;
String secret = CommonConstant.TEMP_TOKEN_SECRET;
// 模拟登录生成Token
String token = JwtUtil.sign(username, secret);
// 设置Token缓存有效时间为 5 分钟
redisUtil.set(RedisConstant.THREAD_TOKEN, token, 5 * 60);
return token;
}
}

View File

@ -0,0 +1,14 @@
package org.jeecg.modules.base.entity.monitor;
import lombok.Data;
import java.io.Serializable;
@Data
public class History implements Serializable {
private String name;
private Long date;
private Double value;
}

View File

@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@ -20,4 +21,6 @@ public class ItemHistory implements Serializable {
private String name;
private String units;
private List<History> list;
}

View File

@ -16,6 +16,7 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.jeecg.common.system.base.entity.JeecgEntity;
import org.jeecg.modules.base.dto.NuclideInfo;
import org.springframework.format.annotation.DateTimeFormat;
import org.jeecgframework.poi.excel.annotation.Excel;
@ -24,11 +25,8 @@ import org.jeecgframework.poi.excel.annotation.Excel;
@TableName("alarm_analysis_log")
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class AlarmAnalysisLog implements Serializable{
@TableId(type = IdType.ASSIGN_ID)
private String id;
public class AlarmAnalysisLog extends JeecgEntity implements Serializable{
private String ruleId;
private String stationId;
@ -51,6 +49,10 @@ public class AlarmAnalysisLog implements Serializable{
private String sampleName;
private String sampleType;
private String analyst;
@TableField(exist = false)
private List<NuclideInfo> nuclideInfoList;
}

View File

@ -28,6 +28,9 @@ public class SysDatabase implements Serializable {
@TableField(value = "name")
private String name;
@TableField(value = "host_id")
private String hostId;
/**
* 用户名称
*/

View File

@ -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<SysEmail> list = ListUtil.toList(email1, email2);
List<CompletableFuture<Void>> 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("测试异常");
}
}

View File

@ -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,8 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static org.jeecg.modules.base.enums.Qiye.IS;
@ -94,7 +97,30 @@ public class StatusAspect {
Object[] args = point.getArgs();
if (ArrayUtil.length(args) == 0) return;
SysDatabase database = (SysDatabase) args[0];
databaseService.status2Redis(database);
try {
databaseService.status2Redis(database);
String token = ManageUtil.getToken();
Page<Host> hostPage = monitorAlarm.dbList(null, 1, 99, token).getResult();
if (ObjectUtil.isNull(hostPage) || CollUtil.isEmpty(hostPage.getRecords()))
return;
List<Host> hosts = hostPage.getRecords();
String name = database.getName();
Host host = null;
for (Host oneHost : hosts) {
if (StrUtil.equals(name, oneHost.getCode()))
host = oneHost;
}
if (ObjectUtil.isNull(host))
return;
// 更新数据源的HostId
database.setHostId(host.getHostId());
databaseService.updateById(database);
}catch (FeignException.Unauthorized e){
ManageUtil.refreshToken();
log.warn("向运管系统查询Hosts信息异常: Token失效,已刷新Token");
}catch (Exception e){
log.error("数据源更新状态/绑定HostId异常: {}", e.getMessage());
}
}
/*
@ -124,27 +150,24 @@ public class StatusAspect {
List<Host> hosts = hostPage.getRecords();
Host host = null;
for (Host oneHost : hosts) {
String code = oneHost.getCode();
if (StrUtil.equals(ipAddress, code))
if (StrUtil.equals(ipAddress, oneHost.getCode()))
host = oneHost;
}
if (ObjectUtil.isNull(host)){
redisUtil.hset(key, id, new NameValue(name, status));
return;
}
status = host.getStatus();
String hostId = host.getHostId();
server.setHostId(hostId);
// 更新该服务器状态信息
status = host.getStatus();
redisUtil.hset(key, id, new NameValue(name, status));
// 更新该服务器的HostId
server.setHostId(host.getHostId());
serverService.updateById(server);
// 同步服务器监控项
Page<Item> itemPage = monitorAlarm.allItems(hostId,
MonitorConstant.pageNo, MonitorConstant.pageSize, token).getResult();
if (ObjectUtil.isNull(itemPage) || CollUtil.isEmpty(itemPage.getRecords()))
Map<String, Item> itemMap = host.getItems();
if (MapUtil.isEmpty(itemMap) || CollUtil.isEmpty(itemMap.values()))
return;
List<Item> items = itemPage.getRecords();
Collection<Item> items = itemMap.values();
List<AlarmItem> alarmItems = new ArrayList<>();
items.forEach(item -> {
AlarmItem alarmItem = BeanUtil.copyProperties(item, AlarmItem.class);
@ -156,7 +179,7 @@ public class StatusAspect {
ManageUtil.refreshToken();
log.warn("向运管系统查询Hosts信息异常: Token失效,已刷新Token");
}catch (Exception e){
log.error("向运管系统查询Hosts信息异常: {}", e.getMessage());
log.error("服务器更新状态/绑定HostId/绑定监控项异常: {}", e.getMessage());
}
}
@ -184,8 +207,8 @@ public class StatusAspect {
@AfterReturning("execution(* org.jeecg.modules.service.impl.SysEmailServiceImpl.deleteById(..)) || " +
"execution(* org.jeecg.modules.service.impl.SysDatabaseServiceImpl.deleteById(..))")
public void deleteRules(JoinPoint point){
Object[] args = point.getArgs();
// 删除数据库和邮箱相关联的报警规则
Object[] args = point.getArgs();
if (ArrayUtil.length(args) > 0)
alarmRuleService.deleteBySourceId((String) args[0]);
}

View File

@ -21,12 +21,6 @@ import java.util.stream.Collectors;
@RequestMapping("alarmItem")
public class AlarmItemController extends JeecgController<AlarmItem, IAlarmItemService> {
@GetMapping("syncServerItem")
@ApiOperation(value = "同步服务器监控项信息",notes = "同步服务器监控项信息")
public boolean syncServerItem(){
return service.syncServerItem();
}
@GetMapping("alarmItems")
@ApiOperation(value = "服务器所有监控项",notes = "服务器所有监控项")
public Result<?> alarmItems(@RequestParam String sourceId){

View File

@ -23,43 +23,43 @@ public class SysDatabaseController {
@GetMapping("findPage")
@ApiOperation(value = "分页查询数据库配置信息", notes = "分页查询数据库配置信息")
public Result findPage(QueryRequest query){
public Result<?> findPage(QueryRequest query){
return sysDatabaseService.findPage(query);
}
@GetMapping("findInfo")
@ApiOperation(value = "查询数据库配置信息详情", notes = "查询数据库配置信息详情")
public Result findInfo(String id){
public Result<?> findInfo(String id){
return sysDatabaseService.findInfo(id);
}
@PostMapping("create")
@ApiOperation(value = "新增数据库配置信息", notes = "新增数据库配置信息")
public Result create(@RequestBody SysDatabase sysDatabase){
public Result<?> create(@RequestBody SysDatabase sysDatabase){
return sysDatabaseService.create(sysDatabase);
}
@PutMapping("update")
@ApiOperation(value = "修改数据库配置信息", notes = "修改数据库配置信息")
public Result update(@RequestBody SysDatabase sysDatabase){
public Result<?> update(@RequestBody SysDatabase sysDatabase){
return sysDatabaseService.update(sysDatabase);
}
@DeleteMapping("deleteById")
@ApiOperation(value = "删除数据库配置信息", notes = "删除数据库配置信息")
public Result deleteById(String id){
public Result<?> deleteById(String id){
return sysDatabaseService.deleteById(id);
}
@GetMapping("findAlarmHistory")
@ApiOperation(value = "查询数据库历史报警信息", notes = "查询数据库历史报警信息")
public Result findAlarmHistory(SourceVo sourceVo){
public Result<?> findAlarmHistory(SourceVo sourceVo){
return sysDatabaseService.findAlarmHistory(sourceVo);
}
@GetMapping("sourceList")
@ApiOperation(value = "数据库服务名列表",notes = "数据库服务名列表")
public Result sourceList(){
public Result<?> sourceList(){
List<SourceDto> sourceDtos = sysDatabaseService.listAll();
return Result.OK(sourceDtos);
}

View File

@ -5,6 +5,7 @@ import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.feignclient.ManageUtil;
import org.jeecg.modules.feignclient.MonitorAlarm;
import org.jeecg.modules.service.IMonitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -19,9 +20,12 @@ public class SystemMonitorController {
@Autowired
private MonitorAlarm monitorAlarm;
@Autowired
private IMonitorService monitorService;
@GetMapping("list")
@ApiOperation(value = "服务器列表详情信息", notes = "服务器列表详情信息")
Result<?> list(String code, String hostId,
public Result<?> list(String code, String hostId,
Integer pageNo, Integer pageSize,
String status, String type){
String token = ManageUtil.getToken();
@ -30,31 +34,41 @@ public class SystemMonitorController {
@GetMapping("queryHostDetails")
@ApiOperation(value = "单个服务器监控项信息", notes = "单个服务器监控项信息")
Result<?> detail(@RequestParam String hostId,
@RequestParam String pageName,
Integer pageNo, Integer pageSize,
String start, String end){
public Result<?> detail(@RequestParam String hostId,
@RequestParam String pageName,
Integer pageNo, Integer pageSize,
String start, String end){
String token = ManageUtil.getToken();
return monitorAlarm.detail(hostId, pageName, pageNo, pageSize, start, end, token);
}
@GetMapping("queryItemHistory")
@ApiOperation(value = "监控项历史数据信息", notes = "监控项历史数据信息")
Result<?> item(@RequestParam String itemId,
@RequestParam Integer itemType,
@RequestParam String start,
@RequestParam String end){
public Result<?> item(@RequestParam String itemId,
@RequestParam Integer itemType,
@RequestParam String start,
@RequestParam String end){
String token = ManageUtil.getToken();
return monitorAlarm.item(itemId, itemType, start, end, token);
}
@GetMapping("queryItemHistoryData")
@ApiOperation(value = "监控项历史数据", notes = "监控项历史数据")
Result<?> itemData(@RequestParam String itemId,
@RequestParam Integer itemType,
@RequestParam String start,
@RequestParam String end){
public Result<?> itemData(@RequestParam String itemId,
@RequestParam Integer itemType,
@RequestParam String start,
@RequestParam String end){
String token = ManageUtil.getToken();
return monitorAlarm.itemData(itemId, itemType, start, end, token);
}
/* ---------------------- 数据库相关接口 ---------------------- */
@GetMapping("dbDetail")
@ApiOperation(value = "数据库指标信息", notes = "数据库指标信息")
public Result<?> dbDetail(@RequestParam("hostId") String hostId,
@RequestParam("start") String start,
@RequestParam("end") String end){
String token = ManageUtil.getToken();
return monitorAlarm.dbDetail(hostId, start, end, token);
}
}

View File

@ -39,6 +39,7 @@ public class ManageUtil {
LoginVo loginVo = new LoginVo(username, password);
Result<LoginResult> loginRes = monitorAlarm.login(loginVo);
String token = loginRes.getResult().getToken();
// 有效期为 12h
redisUtil.set(RedisConstant.MANAGE_TOKEN, token, JwtUtil.EXPIRE_TIME / 1000 - 10);
return token;
}
@ -47,6 +48,7 @@ public class ManageUtil {
LoginVo loginVo = new LoginVo(username, password);
Result<LoginResult> loginRes = monitorAlarm.login(loginVo);
String token = loginRes.getResult().getToken();
// 有效期为 12h
redisUtil.set(RedisConstant.MANAGE_TOKEN, token, JwtUtil.EXPIRE_TIME / 1000 - 10);
}
}

View File

@ -43,12 +43,6 @@ public interface MonitorAlarm {
@RequestParam("pageSize") Integer pageSize,
@RequestHeader("X-Access-Token") String token);
@GetMapping("/omms/device/monitor/queryAllItems")
Result<Page<Item>> 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<Host> summary(@RequestParam("hostId") String hostId,
@RequestParam("pageName") String pageName,
@ -116,9 +110,14 @@ public interface MonitorAlarm {
// -------------------------------------------数据库相关-----------------------------------------------------
@GetMapping("/omms/monitor/db/item/detail")
Result<?> dbDetail(@RequestParam("hostId") String hostId,
@RequestHeader("X-Access-Token") String token);
Result<List<ItemHistory>> dbDetail(@RequestParam("hostId") String hostId,
@RequestParam("start") String start,
@RequestParam("end") String end,
@RequestHeader("X-Access-Token") String token);
@GetMapping("/omms/monitor/db/list")
Result<?> dbList(@RequestHeader("X-Access-Token") String token);
Result<Page<Host>> dbList(@RequestParam("code") String code,
@RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize,
@RequestHeader("X-Access-Token") String token);
}

View File

@ -14,6 +14,7 @@ import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.config.mqtoken.UserTokenContext;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.SymbolConstant;
import org.jeecg.common.constant.enums.SampleType;
import org.jeecg.common.util.RedisStreamUtil;
import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.modules.base.dto.NuclideInfo;
@ -186,6 +187,9 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
// 保存报警日志
AlarmAnalysisLog logInfo = new AlarmAnalysisLog();
BeanUtil.copyProperties(info,logInfo);
SampleType sampleType = SampleType.typeOf(betaOrGamma);
if (ObjectUtil.isNotNull(sampleType))
logInfo.setSampleType(sampleType.getValue());
if (alarmInfo.toString().startsWith(comma))
alarmInfo = new StringBuilder(StrUtil.sub(alarmInfo.toString(), 1, alarmInfo.length()));
logInfo.setAlarmInfo(alarmInfo.toString());

View File

@ -8,7 +8,6 @@ import org.jeecg.modules.base.entity.postgre.AlarmItem;
import java.util.List;
public interface IAlarmItemService extends IService<AlarmItem> {
boolean syncServerItem();
void deleteByHostId(String serverId);

View File

@ -0,0 +1,16 @@
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;
import org.jeecg.modules.base.bizVo.SourceVo;
import org.jeecg.modules.base.dto.SourceDto;
import org.jeecg.modules.base.entity.postgre.SysServer;
import java.util.List;
public interface IMonitorService{
void dbDetails(String start, String end, String hostId);
}

View File

@ -45,46 +45,9 @@ import static org.jeecg.modules.base.enums.SourceType.SERVER;
@Slf4j
public class AlarmItemServiceImpl extends ServiceImpl<AlarmItemMapper, AlarmItem> implements IAlarmItemService {
@Autowired
private MonitorAlarm monitorAlarm;
@Autowired
private ISysServerService serverService;
@Autowired
private IAlarmItemDeService alarmItemDeService;
@Transactional
public boolean syncServerItem() {
try {
// 获取所有监控服务器信息(不包括数据库服务)
String token = ManageUtil.getToken();
List<Host> hosts = monitorAlarm.listApp(MonitorConstant.SERVER_APP,
MonitorConstant.pageNo, MonitorConstant.pageSize, token).getResult().getRecords();
// 获取所有服务器信息
List<SysServer> servers = serverService.list();
List<String> hostIds = servers.stream().map(SysServer::getHostId).filter(StrUtil::isNotBlank)
.collect(Collectors.toList());
// 收集监控服务器列表中当前系统录入的服务器 并将收集所有监控项
List<Item> items = hosts.stream().filter(host -> CollUtil.contains(hostIds, host.getHostId()))
.flatMap(host -> host.getItems().values().stream())
.collect(Collectors.toList());
List<AlarmItem> alarmItems = new ArrayList<>();
for (Item item : items) {
AlarmItem alarmItem = BeanUtil.copyProperties(item, AlarmItem.class);
alarmItem.setId(item.getItemId());
alarmItems.add(alarmItem);
}
return saveOrUpdateBatch(alarmItems);
}catch (FeignException.Unauthorized e){
ManageUtil.refreshToken();
log.warn("向运管系统同步Server监控项信息异常: Token失效,已刷新Token");
return false;
} catch (Exception e){
log.error("向运管系统同步Server监控项信息异常: {}", e.getMessage());
return false;
}
}
@Override
public void deleteByHostId(String hostId) {

View File

@ -0,0 +1,54 @@
package org.jeecg.modules.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import feign.FeignException;
import lombok.extern.slf4j.Slf4j;
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.constant.RedisConstant;
import org.jeecg.common.util.NumUtil;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.base.bizVo.SourceVo;
import org.jeecg.modules.base.dto.*;
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.enums.ServerStatus;
import org.jeecg.modules.entity.AlarmHistory;
import org.jeecg.modules.feignclient.ManageUtil;
import org.jeecg.modules.feignclient.MonitorAlarm;
import org.jeecg.modules.mapper.SysServerMapper;
import org.jeecg.modules.service.IMonitorService;
import org.jeecg.modules.service.ISysServerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@Service
public class MonitorServiceImpl implements IMonitorService {
@Autowired
private MonitorAlarm monitorAlarm;
@Override
public void dbDetails(String start, String end, String hostId) {
}
}

View File

@ -86,7 +86,7 @@ public class SysDatabaseServiceImpl extends ServiceImpl<SysDatabaseMapper, SysDa
databaseDto.setDataBaseType(dataBaseType)
.setOnline(online).setSlowQuery("328/s")
.setAlarmRed(true).setCpuUutilzation("35.8%")
.setMemoryUsage("55.8%").setDiskUsage("35.68%");
.setMemoryUsage("55.8%").setDiskUsage("35.6%");
}
page.setRecords(databaseDtos);
return Result.OK(page);
@ -211,6 +211,7 @@ public class SysDatabaseServiceImpl extends ServiceImpl<SysDatabaseMapper, SysDa
List<SourceDto> sourceDtos = new ArrayList<>();
for (SysDatabase sysDatabase : list(wrapper)) {
SourceDto sourceDto = new SourceDto();
sourceDto.setHostId(sysDatabase.getHostId());
sourceDto.setSourceId(sysDatabase.getId());
sourceDto.setSourceName(sysDatabase.getName());
sourceDtos.add(sourceDto);

View File

@ -109,17 +109,19 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
if (ObjectUtil.isNull(host))
continue;
Map<String, Item> 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<SysServerMapper, SysServer
empty = items.get(MonitorConstant.ITEM_CPUTYPE);
String cpuType = ObjectUtil.isNull(empty) ? "--" : empty.getLastValue();
/* CPU MEMORY LOADS DISK */
// CPU利用率
empty = items.get(MonitorConstant.ITEM_CPUUSED);
String cpuUsed = ObjectUtil.isNull(empty) ? null : empty.getLastValue(); // 0.24
Double cpuUsedValue = NumUtil.keep(cpuUsed, 3);
cpuUsedValue = ObjectUtil.isNull(cpuUsedValue) ? 0 : cpuUsedValue * 100;
String cpuUsed = ObjectUtil.isNull(empty) ? null : empty.getLastValue(); // 23.34
Double cpuUsedValue = NumUtil.keep(cpuUsed, 1);
cpuUsedValue = ObjectUtil.isNull(cpuUsedValue) ? 0 : cpuUsedValue;
// 内存利用率
empty = items.get(MonitorConstant.ITEM_MEMORYUSED);
String memoryUsed = ObjectUtil.isNull(empty) ? null : empty.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()));

View File

@ -37,10 +37,6 @@ public interface AbnormalAlarmClient {
@GetMapping("/nuclideParam/refresh")
boolean refreshParam();
/* AlarmItemController下相关接口 */
@GetMapping("/alarmItem/syncServerItem")
boolean syncServerItem();
/* SysDatabaseController下相关接口 */
@GetMapping("/sysDatabase/getNameById")
String getDatabaseName(@RequestParam String id);

View File

@ -1,6 +1,7 @@
package org.jeecg.modules.quartz.job;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.TokenContext;
import org.jeecg.common.config.mqtoken.UserTokenContext;
import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.modules.feignclient.AbnormalAlarmClient;
@ -21,28 +22,14 @@ import static org.jeecg.common.util.TokenUtils.getTempToken;
@PersistJobDataAfterExecution
public class NuclideParamJob implements Job {
private AbnormalAlarmClient alarmClient;
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
try {
init();
try (TokenContext tokenContext = new TokenContext()){
tokenContext.setToken();
AbnormalAlarmClient alarmClient = SpringContextUtils.getBean(AbnormalAlarmClient.class);
alarmClient.refreshParam();
}catch (Exception e){
e.printStackTrace();
}finally {
destroy();
log.error("定时任务[NuclideParamJob]执行异常: {}", e.getMessage());
}
}
private void init(){
// start:生成临时Token到线程中
UserTokenContext.setToken(getTempToken());
alarmClient = SpringContextUtils.getBean(AbnormalAlarmClient.class);
}
private void destroy(){
// end:删除临时Token
UserTokenContext.remove();
}
}

View File

@ -1,6 +1,7 @@
package org.jeecg.modules.quartz.job;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.TokenContext;
import org.jeecg.common.config.mqtoken.UserTokenContext;
import org.jeecg.common.constant.DateConstant;
import org.jeecg.common.util.SpringContextUtils;
@ -25,32 +26,18 @@ import static org.jeecg.common.util.TokenUtils.getTempToken;
@PersistJobDataAfterExecution
public class NucliedAvgJob implements Job {
private AbnormalAlarmClient alarmClient;
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
try {
init();
try (TokenContext tokenContext = new TokenContext()){
tokenContext.setToken();
AbnormalAlarmClient alarmClient = SpringContextUtils.getBean(AbnormalAlarmClient.class);
alarmClient.calculateConc();
log.info(log());
}catch (Exception e){
e.printStackTrace();
}finally {
destroy();
log.error("定时任务[NucliedAvgJob]执行异常: {}", e.getMessage());
}
}
private void init(){
// start:生成临时Token到线程中
UserTokenContext.setToken(getTempToken());
alarmClient = SpringContextUtils.getBean(AbnormalAlarmClient.class);
}
private void destroy(){
// end:删除临时Token
UserTokenContext.remove();
}
private String log(){
String now = LocalDateTime.now()
.format(DateTimeFormatter.ofPattern(DateConstant.DATE_TIME));

View File

@ -1,42 +0,0 @@
package org.jeecg.modules.quartz.job;
import org.jeecg.common.config.mqtoken.UserTokenContext;
import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.modules.feignclient.AbnormalAlarmClient;
import org.quartz.*;
import static org.jeecg.common.util.TokenUtils.getTempToken;
/**
* 此处的同步是指:当定时任务的执行时间大于任务的时间
* 间隔时会等待第一个任务执行完成才会走第二个任务
*/
@DisallowConcurrentExecution
@PersistJobDataAfterExecution
public class SyncServerItemJob implements Job {
private AbnormalAlarmClient alarmClient;
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
try {
init();
alarmClient.syncServerItem();
}catch (Exception e){
e.printStackTrace();
}finally {
destroy();
}
}
private void init(){
// start:生成临时Token到线程中
UserTokenContext.setToken(getTempToken());
alarmClient = SpringContextUtils.getBean(AbnormalAlarmClient.class);
}
private void destroy(){
// end:删除临时Token
UserTokenContext.remove();
}
}