feat:1.使用信息模板2.线程换为定时调度3.修复服务器摘要信息bug
This commit is contained in:
parent
977447bd07
commit
73bc57561a
|
@ -115,9 +115,9 @@ public class MessageDTO implements Serializable {
|
|||
this.content = content;
|
||||
}
|
||||
|
||||
public MessageDTO(String title, String content, String toUser) {
|
||||
public MessageDTO(String title, String template, String toUser) {
|
||||
this.title = title;
|
||||
this.content = content;
|
||||
this.templateCode = template;
|
||||
this.toUser = toUser;
|
||||
}
|
||||
|
||||
|
|
|
@ -60,8 +60,8 @@ public class JDBCUtil {
|
|||
try (Connection connection = dataSource.getConnection()) {
|
||||
return new ConnR().setConn(true);
|
||||
} catch (SQLException e) {
|
||||
String message = String.format("[xxx数据源]连接失败: %s", e.getMessage());
|
||||
return new ConnR().setInfo(message);
|
||||
// String message = String.format("[xxx数据源]连接失败: %s", e.getMessage());
|
||||
return new ConnR().setInfo(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
package org.jeecg.modules;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.common.constant.RedisConstant;
|
||||
import org.jeecg.common.util.JDBCUtil;
|
||||
import org.jeecg.common.util.RedisUtil;
|
||||
import org.jeecg.common.util.SpringContextUtils;
|
||||
import org.jeecg.modules.base.entity.postgre.SysDatabase;
|
||||
import org.jeecg.modules.service.ISysDatabaseService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DatabaseStatusManager {
|
||||
|
||||
public void start() {
|
||||
DbStatusThread dbStatusThread = new DbStatusThread();
|
||||
dbStatusThread.start();
|
||||
}
|
||||
|
||||
private static class DbStatusThread extends Thread{
|
||||
|
||||
private long sleepTime;
|
||||
|
||||
private ISysDatabaseService databaseService;
|
||||
|
||||
private DbStatusThread(){
|
||||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
try {
|
||||
databaseService.status2Redis();
|
||||
} catch (Exception e) {
|
||||
log.error("DatabaseStatusManager.run()异常: {}", e.getMessage());
|
||||
}finally {
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(sleepTime);
|
||||
} catch (InterruptedException e) {
|
||||
log.error("DatabaseStatusManager.sleep()异常: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void init(){
|
||||
sleepTime = 5 * 1000; // 睡眠时间5s
|
||||
databaseService = SpringContextUtils.getBean(ISysDatabaseService.class);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,36 +17,10 @@ import java.util.concurrent.*;
|
|||
public class Demo {
|
||||
|
||||
public static void main(String[] args) {
|
||||
EmailServiceManager manager = EmailServiceManager.getInstance();
|
||||
SysEmail email = new SysEmail();
|
||||
// Get
|
||||
email.setEmailServerAddress("imap.qiye.163.com");
|
||||
email.setUsername("cnndc.rn.ng@ndc.org.cn");
|
||||
email.setPassword("cnndc66367220");
|
||||
email.setPort(993);
|
||||
|
||||
/*email.setEmailServerAddress("imap.exmail.qq.com");
|
||||
email.setUsername("xiaoguangbin@hivekion.com");
|
||||
email.setPassword("Ans9sLY4kVnux7ai");
|
||||
email.setPort(143);
|
||||
|
||||
// Send
|
||||
email.setEmailServerAddress("smtphz.qiye.163.com");
|
||||
email.setUsername("cnndc.rn.ng@ndc.org.cn");
|
||||
email.setPassword("cnndc66367220");
|
||||
email.setPort(465);
|
||||
|
||||
email.setEmailServerAddress("smtp.163.com");
|
||||
email.setUsername("armd_auto@163.com");
|
||||
email.setPassword("NVOWHFOGWVOFILVV");
|
||||
email.setPort(25);*/
|
||||
|
||||
/*manager.init(email);
|
||||
long start = System.currentTimeMillis();
|
||||
System.out.println(manager.canReceiveSSL() || manager.canReceive());
|
||||
long end = System.currentTimeMillis();
|
||||
System.out.println("连接耗时: " + (end - start) / 1000 + "s");*/
|
||||
test();
|
||||
Executor executor = Executors.newFixedThreadPool(3);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
CompletableFuture.runAsync(Demo::test2, executor);
|
||||
}
|
||||
}
|
||||
|
||||
public static void test(){
|
||||
|
@ -86,4 +60,8 @@ public class Demo {
|
|||
e.printStackTrace();
|
||||
}*/
|
||||
}
|
||||
|
||||
public static void test2(){
|
||||
throw new RuntimeException("测试异常");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
package org.jeecg.modules;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.common.constant.RedisConstant;
|
||||
import org.jeecg.common.util.EmailUtil;
|
||||
import org.jeecg.common.util.JDBCUtil;
|
||||
import org.jeecg.common.util.RedisUtil;
|
||||
import org.jeecg.common.util.SpringContextUtils;
|
||||
import org.jeecg.modules.base.entity.postgre.SysDatabase;
|
||||
import org.jeecg.modules.base.entity.postgre.SysEmail;
|
||||
import org.jeecg.modules.service.ISysDatabaseService;
|
||||
import org.jeecg.modules.service.ISysEmailService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class EmailStatusManager {
|
||||
|
||||
public void start() {
|
||||
EmailStatusThread emailStatusThread = new EmailStatusThread();
|
||||
emailStatusThread.start();
|
||||
}
|
||||
|
||||
private static class EmailStatusThread extends Thread{
|
||||
|
||||
private long sleepTime;
|
||||
|
||||
private ISysEmailService emailService;
|
||||
|
||||
private EmailStatusThread(){
|
||||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (true){
|
||||
try {
|
||||
emailService.status2Redis();
|
||||
} catch (Exception e) {
|
||||
log.error("EmailStatusManager.run()异常: {}", e.getMessage());
|
||||
}finally {
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(sleepTime);
|
||||
} catch (InterruptedException e) {
|
||||
log.error("EmailStatusManager.sleep()异常: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void init(){
|
||||
sleepTime = 5 * 60 * 1000; // 睡眠时间5min
|
||||
emailService = SpringContextUtils.getBean(ISysEmailService.class);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
package org.jeecg.modules;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.common.util.SpringContextUtils;
|
||||
import org.jeecg.modules.service.ISysDatabaseService;
|
||||
import org.jeecg.modules.service.ISysServerService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ServerStatusManager {
|
||||
|
||||
public void start() {
|
||||
ServerStatusThread serverStatusThread = new ServerStatusThread();
|
||||
serverStatusThread.start();
|
||||
}
|
||||
|
||||
private static class ServerStatusThread extends Thread{
|
||||
|
||||
private long sleepTime;
|
||||
|
||||
private ISysServerService serverService;
|
||||
|
||||
private ServerStatusThread(){
|
||||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
try {
|
||||
serverService.status2Redis();
|
||||
} catch (Exception e) {
|
||||
log.error("ServerStatusManager.run()异常: {}", e.getMessage());
|
||||
}finally {
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(sleepTime);
|
||||
} catch (InterruptedException e) {
|
||||
log.error("ServerStatusManager.sleep()异常: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void init(){
|
||||
sleepTime = 5 * 1000; // 睡眠时间5s
|
||||
serverService = SpringContextUtils.getBean(ISysServerService.class);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -28,6 +28,8 @@ import org.jeecg.modules.qiyeEmail.base.InstanceSDK;
|
|||
import org.jeecg.modules.qiyeEmail.base.RParam;
|
||||
import org.jeecg.modules.qiyeEmail.base.dto.AccountInfo;
|
||||
import org.jeecg.modules.qiyeEmail.service.Account;
|
||||
import org.jeecg.modules.service.IAlarmRuleService;
|
||||
import org.jeecg.modules.service.ISysDatabaseService;
|
||||
import org.jeecg.modules.service.ISysEmailService;
|
||||
import org.jeecg.modules.service.ISysServerService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -56,17 +58,22 @@ public class StatusAspect {
|
|||
@Autowired
|
||||
private ISysServerService serverService;
|
||||
|
||||
@Autowired
|
||||
private ISysDatabaseService databaseService;
|
||||
|
||||
@Autowired
|
||||
private IAlarmRuleService alarmRuleService;
|
||||
|
||||
// 新增|修改邮箱服务器信息后 异步更新其状态信息
|
||||
@Async
|
||||
@AfterReturning("execution(* org.jeecg.modules.service.impl.SysEmailServiceImpl.update(..)) || " +
|
||||
"execution(* org.jeecg.modules.service.impl.SysEmailServiceImpl.create(..))")
|
||||
public void updateEamilStatus(JoinPoint point){
|
||||
Object[] args = point.getArgs();
|
||||
if (ArrayUtil.length(args) > 0){
|
||||
if (ArrayUtil.length(args) == 0) return;
|
||||
SysEmail email = (SysEmail) args[0];
|
||||
emailService.status2Redis(email);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 新增|修改数据源信息后 异步更新其状态信息
|
||||
|
@ -76,18 +83,9 @@ public class StatusAspect {
|
|||
"execution(* org.jeecg.modules.service.impl.SysDatabaseServiceImpl.create(..))")
|
||||
public void updateDatabaseStatus(JoinPoint point){
|
||||
Object[] args = point.getArgs();
|
||||
if (ArrayUtil.length(args) > 0) {
|
||||
if (ArrayUtil.length(args) == 0) return;
|
||||
SysDatabase database = (SysDatabase) args[0];
|
||||
String id = database.getId();
|
||||
String name = database.getName();
|
||||
String dbUrl = database.getDbUrl();
|
||||
String dbDriver = database.getDbDriver();
|
||||
String dbUsername = database.getDbUsername();
|
||||
String dbPassword = database.getDbPassword();
|
||||
boolean isConn = JDBCUtil.isConnection(dbUrl, dbDriver, dbUsername, dbPassword);
|
||||
String statusKey = RedisConstant.DATABASE_STATUS;
|
||||
redisUtil.hset(statusKey, id, new NameValue(name, isConn));
|
||||
}
|
||||
databaseService.status2Redis(database);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -99,7 +97,7 @@ public class StatusAspect {
|
|||
"execution(* org.jeecg.modules.service.impl.SysServerServiceImpl.create(..))")
|
||||
public void updateServerStatus(JoinPoint point){
|
||||
Object[] args = point.getArgs();
|
||||
if (ArrayUtil.length(args) > 0) {
|
||||
if (ArrayUtil.length(args) == 0) return;
|
||||
String key = RedisConstant.SERVER_STATUS;
|
||||
String status = ServerStatus.UNKNOWN.getValue(); // 初始值为-1
|
||||
SysServer server = (SysServer) args[0];
|
||||
|
@ -129,5 +127,17 @@ public class StatusAspect {
|
|||
log.error("向运管系统查询Hosts信息异常: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 删除Email|Database|Server时 同步删除Redis和数据库中相关联的预警规则
|
||||
* */
|
||||
@Async
|
||||
@AfterReturning("execution(* org.jeecg.modules.service.impl.SysServerServiceImpl.deleteById(..)) ||" +
|
||||
"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();
|
||||
if (ArrayUtil.length(args) > 0)
|
||||
alarmRuleService.deleteBySourceId((String) args[0]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ import org.springframework.stereotype.Component;
|
|||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.jeecg.common.util.TokenUtils.getTempToken;
|
||||
|
@ -50,7 +52,7 @@ public class IDCDataFetch {
|
|||
@Scheduled(fixedDelayString = "${request-interval}", timeUnit = TimeUnit.SECONDS)
|
||||
public void fetch() {
|
||||
JdbcTemplate template;
|
||||
MessageDTO messageDTO = new MessageDTO("IDC数据源异常", null, "admin");
|
||||
MessageDTO messageDTO = new MessageDTO("IDC数据源异常", "IDC_Datasource_Status", "admin");
|
||||
messageDTO.setType(MessageTypeEnum.XT.getType());
|
||||
ConnR connR = JDBCUtil.isConnection(urlM, usernameM, passwordM);
|
||||
if (connR.isConn()) {
|
||||
|
@ -67,8 +69,12 @@ public class IDCDataFetch {
|
|||
// 对发送警告消息时可能出现的异常进行捕获(503) 防止影响后续代码执行
|
||||
try {
|
||||
// 给管理员发送预警信息
|
||||
String message = StrUtil.replace(connR.getInfo(), "xxx", "inland");
|
||||
messageDTO.setContent(message);
|
||||
/*String message = StrUtil.replace(connR.getInfo(), "xxx", "inland");
|
||||
messageDTO.setContent(message);*/
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("datasource", "inland(测试)");
|
||||
data.put("info", connR.getInfo());
|
||||
messageDTO.setData(data);
|
||||
systemClient.sendTo(messageDTO);
|
||||
}catch (Exception e){
|
||||
log.error("发送inland数据源异常信息失败: {}", e.getMessage());
|
||||
|
|
|
@ -35,5 +35,7 @@ public interface ISysDatabaseService extends IService<SysDatabase> {
|
|||
|
||||
void status2Redis();
|
||||
|
||||
void status2Redis(SysDatabase database);
|
||||
|
||||
String getNameById(String id);
|
||||
}
|
||||
|
|
|
@ -29,12 +29,14 @@ import org.jeecg.modules.service.ISysDatabaseService;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
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;
|
||||
|
||||
import static org.jeecg.common.constant.enums.DbType.*;
|
||||
|
@ -181,9 +183,6 @@ public class SysDatabaseServiceImpl extends ServiceImpl<SysDatabaseMapper, SysDa
|
|||
boolean success = removeById(id);
|
||||
if(success) {
|
||||
delStatus(id);
|
||||
// 同步删除Redis和数据库中的预警规则
|
||||
IAlarmRuleService alarmRuleService = SpringContextUtils.getBean(IAlarmRuleService.class);
|
||||
alarmRuleService.deleteBySourceId(id);
|
||||
return Result.OK(Prompt.DELETE_SUCC);
|
||||
}
|
||||
return Result.error(Prompt.DELETE_ERR);
|
||||
|
@ -311,11 +310,18 @@ public class SysDatabaseServiceImpl extends ServiceImpl<SysDatabaseMapper, SysDa
|
|||
}
|
||||
|
||||
@Override
|
||||
@Scheduled(fixedDelay = 60, timeUnit = TimeUnit.SECONDS)
|
||||
public void status2Redis() {
|
||||
// 获取所有配置的数据源
|
||||
List<SysDatabase> databases = list();
|
||||
Map<String, Object> statusMap = new HashMap<>();
|
||||
for (SysDatabase database : databases) {
|
||||
this.status2Redis(database);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void status2Redis(SysDatabase database) {
|
||||
String statusKey = RedisConstant.DATABASE_STATUS;
|
||||
String id = database.getId();
|
||||
String name = database.getName();
|
||||
String dbUrl = database.getDbUrl();
|
||||
|
@ -323,11 +329,7 @@ public class SysDatabaseServiceImpl extends ServiceImpl<SysDatabaseMapper, SysDa
|
|||
String dbUsername = database.getDbUsername();
|
||||
String dbPassword = database.getDbPassword();
|
||||
boolean isConn = JDBCUtil.isConnection(dbUrl, dbDriver, dbUsername, dbPassword);
|
||||
statusMap.put(id, new NameValue(name, isConn));
|
||||
}
|
||||
// 将数据源连接状态更新到reids
|
||||
String statusKey = RedisConstant.DATABASE_STATUS;
|
||||
redisUtil.hmset(statusKey, statusMap);
|
||||
redisUtil.hset(statusKey, id, new NameValue(name, isConn));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.jeecg.modules.service.IAlarmRuleService;
|
|||
import org.jeecg.modules.service.ISysEmailService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
@ -38,6 +39,7 @@ import java.time.LocalDate;
|
|||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.jeecg.modules.base.enums.Enabled.ENABLED;
|
||||
|
@ -164,9 +166,6 @@ public class SysEmailServiceImpl extends ServiceImpl<SysEmailMapper, SysEmail> i
|
|||
boolean success = this.removeById(id);
|
||||
if (success){
|
||||
delStatus(id);
|
||||
// 同步删除Redis和数据库中的预警规则
|
||||
IAlarmRuleService alarmRuleService = SpringContextUtils.getBean(IAlarmRuleService.class);
|
||||
alarmRuleService.deleteBySourceId(id);
|
||||
return Result.OK(Prompt.DELETE_SUCC);
|
||||
}
|
||||
return Result.error(Prompt.DELETE_ERR);
|
||||
|
@ -218,12 +217,13 @@ public class SysEmailServiceImpl extends ServiceImpl<SysEmailMapper, SysEmail> i
|
|||
}
|
||||
|
||||
@Override
|
||||
@Scheduled(fixedDelay = 60, timeUnit = TimeUnit.SECONDS)
|
||||
public void status2Redis() {
|
||||
// 获取所有配置的邮箱服务器
|
||||
List<SysEmail> emails = list();
|
||||
// 使用并发 更新邮箱状态及用量
|
||||
for (SysEmail email : emails) {
|
||||
CompletableFuture.runAsync(() -> status2Redis(email));
|
||||
CompletableFuture.runAsync(() -> this.status2Redis(email));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ import org.jeecg.common.util.NumUtil;
|
|||
import org.jeecg.common.util.PageUtil;
|
||||
import org.jeecg.common.util.RedisUtil;
|
||||
import org.jeecg.common.util.SpringContextUtils;
|
||||
import org.jeecg.modules.ServerStatusManager;
|
||||
import org.jeecg.modules.base.dto.*;
|
||||
import org.jeecg.modules.base.entity.monitor.Host;
|
||||
import org.jeecg.modules.base.entity.monitor.Item;
|
||||
|
@ -38,6 +37,7 @@ import org.jeecg.modules.mapper.SysServerMapper;
|
|||
import org.jeecg.modules.service.IAlarmRuleService;
|
||||
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;
|
||||
|
||||
|
@ -188,9 +188,6 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
|
|||
boolean success = removeById(id);
|
||||
if(success) {
|
||||
delStatus(id);
|
||||
// 同步删除Redis和数据库中的预警规则
|
||||
IAlarmRuleService alarmRuleService = SpringContextUtils.getBean(IAlarmRuleService.class);
|
||||
alarmRuleService.deleteBySourceId(id);
|
||||
return Result.OK(Prompt.DELETE_SUCC);
|
||||
}
|
||||
return Result.error(Prompt.DELETE_ERR);
|
||||
|
@ -265,31 +262,59 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
|
|||
String status = host.getStatus();
|
||||
boolean online = StrUtil.equals(status, ServerStatus.ON.getValue());
|
||||
Map<String, Item> items = host.getItems();
|
||||
String runTime = items.get(MonitorConstant.ITEM_RUNTIME).getLastValue();
|
||||
runTime = StrUtil.isBlank(runTime) ? "--" :
|
||||
NumUtil.keepStr(Long.parseLong(runTime) / 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();
|
||||
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();
|
||||
Item empty;
|
||||
empty = items.get(MonitorConstant.ITEM_RUNTIME);
|
||||
String runTime = ObjectUtil.isNull(empty) ? "--" :
|
||||
NumUtil.keepStr(Long.parseLong(empty.getLastValue()) / 3600.0, 1) + "h";
|
||||
|
||||
empty = items.get(MonitorConstant.ITEM_RAMSIZE);
|
||||
String ramSize = ObjectUtil.isNull(empty) ? "--" :
|
||||
NumUtil.keepStr(Double.parseDouble(empty.getLastValue().replace("MB", "")) / 1024, 1) + "GB";
|
||||
|
||||
empty = items.get(MonitorConstant.ITEM_CPUCORES);
|
||||
String cpuCores = ObjectUtil.isNull(empty) ? "--" : empty.getLastValue();
|
||||
|
||||
empty = items.get(MonitorConstant.ITEM_TOTALSIDKPAR);
|
||||
String totalDiskPar = ObjectUtil.isNull(empty) ? "--" : empty.getLastValue();
|
||||
|
||||
empty = items.get(MonitorConstant.ITEM_HOSTNAME);
|
||||
String hostName = ObjectUtil.isNull(empty) ? "--" : empty.getLastValue();
|
||||
|
||||
empty = items.get(MonitorConstant.ITEM_OSVERSION);
|
||||
String osVersion = ObjectUtil.isNull(empty) ? "--" : empty.getLastValue();
|
||||
|
||||
empty = items.get(MonitorConstant.ITEM_NETWORK);
|
||||
String netWork = ObjectUtil.isNull(empty) ? "--" : empty.getLastValue();
|
||||
|
||||
empty = items.get(MonitorConstant.ITEM_LOCATION);
|
||||
String location = ObjectUtil.isNull(empty) ? "--" : empty.getLastValue();
|
||||
|
||||
empty = items.get(MonitorConstant.ITEM_IP);
|
||||
String ip = ObjectUtil.isNull(empty) ? "--" : empty.getLastValue();
|
||||
|
||||
empty = items.get(MonitorConstant.ITEM_ZONE);
|
||||
String zone = ObjectUtil.isNull(empty) ? "--" : empty.getLastValue();
|
||||
|
||||
empty = items.get(MonitorConstant.ITEM_OSNAME);
|
||||
String osName = ObjectUtil.isNull(empty) ? "--" : empty.getLastValue();
|
||||
|
||||
empty = items.get(MonitorConstant.ITEM_STARTTIME);
|
||||
String startTime = ObjectUtil.isNull(empty) ? "--" : empty.getLastValue();
|
||||
|
||||
empty = items.get(MonitorConstant.ITEM_CPUTYPE);
|
||||
String cpuType = ObjectUtil.isNull(empty) ? "--" : empty.getLastValue();
|
||||
|
||||
/* CPU MEMORY LOADS DISK */
|
||||
String cpuUsed = items.get(MonitorConstant.ITEM_CPUUSED).getLastValue(); // 0.24
|
||||
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 memoryUsed = items.get(MonitorConstant.ITEM_MEMORYUSED).getLastValue(); // 16.64927
|
||||
|
||||
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()));
|
||||
|
@ -320,6 +345,7 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
|
|||
}
|
||||
|
||||
@Override
|
||||
@Scheduled(fixedDelay = 60, timeUnit = TimeUnit.SECONDS)
|
||||
public void status2Redis() {
|
||||
List<SysServer> sysServers = this.list();
|
||||
String key = RedisConstant.SERVER_STATUS;
|
||||
|
|
|
@ -3,9 +3,6 @@ package org.jeecg;
|
|||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.modules.DatabaseStatusManager;
|
||||
import org.jeecg.modules.EmailStatusManager;
|
||||
import org.jeecg.modules.ServerStatusManager;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
@ -28,12 +25,6 @@ import java.net.UnknownHostException;
|
|||
@RequiredArgsConstructor
|
||||
public class JeecgAbnormalAlarmApplication extends SpringBootServletInitializer implements CommandLineRunner {
|
||||
|
||||
private final ServerStatusManager serverStatusManager;
|
||||
|
||||
private final EmailStatusManager emailStatusManager;
|
||||
|
||||
private final DatabaseStatusManager databaseStatusManager;
|
||||
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
return application.sources(JeecgAbnormalAlarmApplication.class);
|
||||
|
@ -54,12 +45,5 @@ public class JeecgAbnormalAlarmApplication extends SpringBootServletInitializer
|
|||
}
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
// 启动监测数据库连接状态的线程
|
||||
databaseStatusManager.start();
|
||||
// 启动监测邮箱服务器连接状态的线程
|
||||
emailStatusManager.start();
|
||||
// 启动监测服务器连接状态的线程
|
||||
serverStatusManager.start();
|
||||
}
|
||||
public void run(String... args) throws Exception {}
|
||||
}
|
Loading…
Reference in New Issue
Block a user