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;
|
this.content = content;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageDTO(String title, String content, String toUser) {
|
public MessageDTO(String title, String template, String toUser) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.content = content;
|
this.templateCode = template;
|
||||||
this.toUser = toUser;
|
this.toUser = toUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,8 +60,8 @@ public class JDBCUtil {
|
||||||
try (Connection connection = dataSource.getConnection()) {
|
try (Connection connection = dataSource.getConnection()) {
|
||||||
return new ConnR().setConn(true);
|
return new ConnR().setConn(true);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String message = String.format("[xxx数据源]连接失败: %s", e.getMessage());
|
// String message = String.format("[xxx数据源]连接失败: %s", e.getMessage());
|
||||||
return new ConnR().setInfo(message);
|
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 class Demo {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
EmailServiceManager manager = EmailServiceManager.getInstance();
|
Executor executor = Executors.newFixedThreadPool(3);
|
||||||
SysEmail email = new SysEmail();
|
for (int i = 0; i < 3; i++) {
|
||||||
// Get
|
CompletableFuture.runAsync(Demo::test2, executor);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void test(){
|
public static void test(){
|
||||||
|
@ -86,4 +60,8 @@ public class Demo {
|
||||||
e.printStackTrace();
|
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.RParam;
|
||||||
import org.jeecg.modules.qiyeEmail.base.dto.AccountInfo;
|
import org.jeecg.modules.qiyeEmail.base.dto.AccountInfo;
|
||||||
import org.jeecg.modules.qiyeEmail.service.Account;
|
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.ISysEmailService;
|
||||||
import org.jeecg.modules.service.ISysServerService;
|
import org.jeecg.modules.service.ISysServerService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -56,16 +58,21 @@ public class StatusAspect {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysServerService serverService;
|
private ISysServerService serverService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ISysDatabaseService databaseService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IAlarmRuleService alarmRuleService;
|
||||||
|
|
||||||
// 新增|修改邮箱服务器信息后 异步更新其状态信息
|
// 新增|修改邮箱服务器信息后 异步更新其状态信息
|
||||||
@Async
|
@Async
|
||||||
@AfterReturning("execution(* org.jeecg.modules.service.impl.SysEmailServiceImpl.update(..)) || " +
|
@AfterReturning("execution(* org.jeecg.modules.service.impl.SysEmailServiceImpl.update(..)) || " +
|
||||||
"execution(* org.jeecg.modules.service.impl.SysEmailServiceImpl.create(..))")
|
"execution(* org.jeecg.modules.service.impl.SysEmailServiceImpl.create(..))")
|
||||||
public void updateEamilStatus(JoinPoint point){
|
public void updateEamilStatus(JoinPoint point){
|
||||||
Object[] args = point.getArgs();
|
Object[] args = point.getArgs();
|
||||||
if (ArrayUtil.length(args) > 0){
|
if (ArrayUtil.length(args) == 0) return;
|
||||||
SysEmail email = (SysEmail) args[0];
|
SysEmail email = (SysEmail) args[0];
|
||||||
emailService.status2Redis(email);
|
emailService.status2Redis(email);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -76,18 +83,9 @@ public class StatusAspect {
|
||||||
"execution(* org.jeecg.modules.service.impl.SysDatabaseServiceImpl.create(..))")
|
"execution(* org.jeecg.modules.service.impl.SysDatabaseServiceImpl.create(..))")
|
||||||
public void updateDatabaseStatus(JoinPoint point){
|
public void updateDatabaseStatus(JoinPoint point){
|
||||||
Object[] args = point.getArgs();
|
Object[] args = point.getArgs();
|
||||||
if (ArrayUtil.length(args) > 0) {
|
if (ArrayUtil.length(args) == 0) return;
|
||||||
SysDatabase database = (SysDatabase) args[0];
|
SysDatabase database = (SysDatabase) args[0];
|
||||||
String id = database.getId();
|
databaseService.status2Redis(database);
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -99,35 +97,47 @@ public class StatusAspect {
|
||||||
"execution(* org.jeecg.modules.service.impl.SysServerServiceImpl.create(..))")
|
"execution(* org.jeecg.modules.service.impl.SysServerServiceImpl.create(..))")
|
||||||
public void updateServerStatus(JoinPoint point){
|
public void updateServerStatus(JoinPoint point){
|
||||||
Object[] args = point.getArgs();
|
Object[] args = point.getArgs();
|
||||||
if (ArrayUtil.length(args) > 0) {
|
if (ArrayUtil.length(args) == 0) return;
|
||||||
String key = RedisConstant.SERVER_STATUS;
|
String key = RedisConstant.SERVER_STATUS;
|
||||||
String status = ServerStatus.UNKNOWN.getValue(); // 初始值为-1
|
String status = ServerStatus.UNKNOWN.getValue(); // 初始值为-1
|
||||||
SysServer server = (SysServer) args[0];
|
SysServer server = (SysServer) args[0];
|
||||||
String id = server.getId();
|
String id = server.getId();
|
||||||
String name = server.getName();
|
String name = server.getName();
|
||||||
String ipAddress = server.getIpAddress();
|
String ipAddress = server.getIpAddress();
|
||||||
try {
|
try {
|
||||||
String token = ManageUtil.getToken();
|
String token = ManageUtil.getToken();
|
||||||
Servers servers = monitorAlarm.listApp(ipAddress, MonitorConstant.SERVER_APP, token).getResult();
|
Servers servers = monitorAlarm.listApp(ipAddress, MonitorConstant.SERVER_APP, token).getResult();
|
||||||
// 获取所有监控主机信息
|
// 获取所有监控主机信息
|
||||||
List<Host> hosts = servers.getRecords();
|
List<Host> hosts = servers.getRecords();
|
||||||
for (Host host : hosts) {
|
for (Host host : hosts) {
|
||||||
String code = host.getCode();
|
String code = host.getCode();
|
||||||
if (!StrUtil.equals(ipAddress, code))
|
if (!StrUtil.equals(ipAddress, code))
|
||||||
continue;
|
continue;
|
||||||
server.setHostId(host.getHostId());
|
server.setHostId(host.getHostId());
|
||||||
status = host.getStatus();
|
status = host.getStatus();
|
||||||
}
|
|
||||||
// 更新该服务器状态信息
|
|
||||||
redisUtil.hset(key, id, new NameValue(name, status));
|
|
||||||
// 更新该服务器的HostId
|
|
||||||
serverService.updateById(server);
|
|
||||||
}catch (FeignException.Unauthorized e){
|
|
||||||
ManageUtil.refreshToken();
|
|
||||||
log.warn("向运管系统查询Hosts信息异常: Token失效,已刷新Token");
|
|
||||||
}catch (Exception e){
|
|
||||||
log.error("向运管系统查询Hosts信息异常: {}", e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
// 更新该服务器状态信息
|
||||||
|
redisUtil.hset(key, id, new NameValue(name, status));
|
||||||
|
// 更新该服务器的HostId
|
||||||
|
serverService.updateById(server);
|
||||||
|
}catch (FeignException.Unauthorized e){
|
||||||
|
ManageUtil.refreshToken();
|
||||||
|
log.warn("向运管系统查询Hosts信息异常: Token失效,已刷新Token");
|
||||||
|
}catch (Exception e){
|
||||||
|
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.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static org.jeecg.common.util.TokenUtils.getTempToken;
|
import static org.jeecg.common.util.TokenUtils.getTempToken;
|
||||||
|
@ -50,7 +52,7 @@ public class IDCDataFetch {
|
||||||
@Scheduled(fixedDelayString = "${request-interval}", timeUnit = TimeUnit.SECONDS)
|
@Scheduled(fixedDelayString = "${request-interval}", timeUnit = TimeUnit.SECONDS)
|
||||||
public void fetch() {
|
public void fetch() {
|
||||||
JdbcTemplate template;
|
JdbcTemplate template;
|
||||||
MessageDTO messageDTO = new MessageDTO("IDC数据源异常", null, "admin");
|
MessageDTO messageDTO = new MessageDTO("IDC数据源异常", "IDC_Datasource_Status", "admin");
|
||||||
messageDTO.setType(MessageTypeEnum.XT.getType());
|
messageDTO.setType(MessageTypeEnum.XT.getType());
|
||||||
ConnR connR = JDBCUtil.isConnection(urlM, usernameM, passwordM);
|
ConnR connR = JDBCUtil.isConnection(urlM, usernameM, passwordM);
|
||||||
if (connR.isConn()) {
|
if (connR.isConn()) {
|
||||||
|
@ -67,8 +69,12 @@ public class IDCDataFetch {
|
||||||
// 对发送警告消息时可能出现的异常进行捕获(503) 防止影响后续代码执行
|
// 对发送警告消息时可能出现的异常进行捕获(503) 防止影响后续代码执行
|
||||||
try {
|
try {
|
||||||
// 给管理员发送预警信息
|
// 给管理员发送预警信息
|
||||||
String message = StrUtil.replace(connR.getInfo(), "xxx", "inland");
|
/*String message = StrUtil.replace(connR.getInfo(), "xxx", "inland");
|
||||||
messageDTO.setContent(message);
|
messageDTO.setContent(message);*/
|
||||||
|
Map<String, Object> data = new HashMap<>();
|
||||||
|
data.put("datasource", "inland(测试)");
|
||||||
|
data.put("info", connR.getInfo());
|
||||||
|
messageDTO.setData(data);
|
||||||
systemClient.sendTo(messageDTO);
|
systemClient.sendTo(messageDTO);
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
log.error("发送inland数据源异常信息失败: {}", e.getMessage());
|
log.error("发送inland数据源异常信息失败: {}", e.getMessage());
|
||||||
|
|
|
@ -35,5 +35,7 @@ public interface ISysDatabaseService extends IService<SysDatabase> {
|
||||||
|
|
||||||
void status2Redis();
|
void status2Redis();
|
||||||
|
|
||||||
|
void status2Redis(SysDatabase database);
|
||||||
|
|
||||||
String getNameById(String id);
|
String getNameById(String id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,12 +29,14 @@ import org.jeecg.modules.service.ISysDatabaseService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.jdbc.core.RowMapper;
|
import org.springframework.jdbc.core.RowMapper;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
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.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.jeecg.common.constant.enums.DbType.*;
|
import static org.jeecg.common.constant.enums.DbType.*;
|
||||||
|
@ -181,9 +183,6 @@ public class SysDatabaseServiceImpl extends ServiceImpl<SysDatabaseMapper, SysDa
|
||||||
boolean success = removeById(id);
|
boolean success = removeById(id);
|
||||||
if(success) {
|
if(success) {
|
||||||
delStatus(id);
|
delStatus(id);
|
||||||
// 同步删除Redis和数据库中的预警规则
|
|
||||||
IAlarmRuleService alarmRuleService = SpringContextUtils.getBean(IAlarmRuleService.class);
|
|
||||||
alarmRuleService.deleteBySourceId(id);
|
|
||||||
return Result.OK(Prompt.DELETE_SUCC);
|
return Result.OK(Prompt.DELETE_SUCC);
|
||||||
}
|
}
|
||||||
return Result.error(Prompt.DELETE_ERR);
|
return Result.error(Prompt.DELETE_ERR);
|
||||||
|
@ -311,23 +310,26 @@ public class SysDatabaseServiceImpl extends ServiceImpl<SysDatabaseMapper, SysDa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Scheduled(fixedDelay = 60, timeUnit = TimeUnit.SECONDS)
|
||||||
public void status2Redis() {
|
public void status2Redis() {
|
||||||
// 获取所有配置的数据源
|
// 获取所有配置的数据源
|
||||||
List<SysDatabase> databases = list();
|
List<SysDatabase> databases = list();
|
||||||
Map<String, Object> statusMap = new HashMap<>();
|
|
||||||
for (SysDatabase database : databases) {
|
for (SysDatabase database : databases) {
|
||||||
String id = database.getId();
|
this.status2Redis(database);
|
||||||
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);
|
|
||||||
statusMap.put(id, new NameValue(name, isConn));
|
|
||||||
}
|
}
|
||||||
// 将数据源连接状态更新到reids
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void status2Redis(SysDatabase database) {
|
||||||
String statusKey = RedisConstant.DATABASE_STATUS;
|
String statusKey = RedisConstant.DATABASE_STATUS;
|
||||||
redisUtil.hmset(statusKey, statusMap);
|
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);
|
||||||
|
redisUtil.hset(statusKey, id, new NameValue(name, isConn));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.jeecg.modules.service.IAlarmRuleService;
|
||||||
import org.jeecg.modules.service.ISysEmailService;
|
import org.jeecg.modules.service.ISysEmailService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
@ -38,6 +39,7 @@ import java.time.LocalDate;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.jeecg.modules.base.enums.Enabled.ENABLED;
|
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);
|
boolean success = this.removeById(id);
|
||||||
if (success){
|
if (success){
|
||||||
delStatus(id);
|
delStatus(id);
|
||||||
// 同步删除Redis和数据库中的预警规则
|
|
||||||
IAlarmRuleService alarmRuleService = SpringContextUtils.getBean(IAlarmRuleService.class);
|
|
||||||
alarmRuleService.deleteBySourceId(id);
|
|
||||||
return Result.OK(Prompt.DELETE_SUCC);
|
return Result.OK(Prompt.DELETE_SUCC);
|
||||||
}
|
}
|
||||||
return Result.error(Prompt.DELETE_ERR);
|
return Result.error(Prompt.DELETE_ERR);
|
||||||
|
@ -218,12 +217,13 @@ public class SysEmailServiceImpl extends ServiceImpl<SysEmailMapper, SysEmail> i
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Scheduled(fixedDelay = 60, timeUnit = TimeUnit.SECONDS)
|
||||||
public void status2Redis() {
|
public void status2Redis() {
|
||||||
// 获取所有配置的邮箱服务器
|
// 获取所有配置的邮箱服务器
|
||||||
List<SysEmail> emails = list();
|
List<SysEmail> emails = list();
|
||||||
// 使用并发 更新邮箱状态及用量
|
// 使用并发 更新邮箱状态及用量
|
||||||
for (SysEmail email : emails) {
|
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.PageUtil;
|
||||||
import org.jeecg.common.util.RedisUtil;
|
import org.jeecg.common.util.RedisUtil;
|
||||||
import org.jeecg.common.util.SpringContextUtils;
|
import org.jeecg.common.util.SpringContextUtils;
|
||||||
import org.jeecg.modules.ServerStatusManager;
|
|
||||||
import org.jeecg.modules.base.dto.*;
|
import org.jeecg.modules.base.dto.*;
|
||||||
import org.jeecg.modules.base.entity.monitor.Host;
|
import org.jeecg.modules.base.entity.monitor.Host;
|
||||||
import org.jeecg.modules.base.entity.monitor.Item;
|
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.IAlarmRuleService;
|
||||||
import org.jeecg.modules.service.ISysServerService;
|
import org.jeecg.modules.service.ISysServerService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
@ -188,9 +188,6 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
|
||||||
boolean success = removeById(id);
|
boolean success = removeById(id);
|
||||||
if(success) {
|
if(success) {
|
||||||
delStatus(id);
|
delStatus(id);
|
||||||
// 同步删除Redis和数据库中的预警规则
|
|
||||||
IAlarmRuleService alarmRuleService = SpringContextUtils.getBean(IAlarmRuleService.class);
|
|
||||||
alarmRuleService.deleteBySourceId(id);
|
|
||||||
return Result.OK(Prompt.DELETE_SUCC);
|
return Result.OK(Prompt.DELETE_SUCC);
|
||||||
}
|
}
|
||||||
return Result.error(Prompt.DELETE_ERR);
|
return Result.error(Prompt.DELETE_ERR);
|
||||||
|
@ -265,31 +262,59 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
|
||||||
String status = host.getStatus();
|
String status = host.getStatus();
|
||||||
boolean online = StrUtil.equals(status, ServerStatus.ON.getValue());
|
boolean online = StrUtil.equals(status, ServerStatus.ON.getValue());
|
||||||
Map<String, Item> items = host.getItems();
|
Map<String, Item> items = host.getItems();
|
||||||
String runTime = items.get(MonitorConstant.ITEM_RUNTIME).getLastValue();
|
Item empty;
|
||||||
runTime = StrUtil.isBlank(runTime) ? "--" :
|
empty = items.get(MonitorConstant.ITEM_RUNTIME);
|
||||||
NumUtil.keepStr(Long.parseLong(runTime) / 3600.0, 1) + "h";
|
String runTime = ObjectUtil.isNull(empty) ? "--" :
|
||||||
String ramSize = items.get(MonitorConstant.ITEM_RAMSIZE).getLastValue();
|
NumUtil.keepStr(Long.parseLong(empty.getLastValue()) / 3600.0, 1) + "h";
|
||||||
ramSize = StrUtil.isBlank(ramSize) ? "--" :
|
|
||||||
NumUtil.keepStr(Double.parseDouble(ramSize.replace("MB", "")) / 1024, 1) + "GB";
|
empty = items.get(MonitorConstant.ITEM_RAMSIZE);
|
||||||
String cpuCores = items.get(MonitorConstant.ITEM_CPUCORES).getLastValue();
|
String ramSize = ObjectUtil.isNull(empty) ? "--" :
|
||||||
String totalDiskPar = items.get(MonitorConstant.ITEM_TOTALSIDKPAR).getLastValue();
|
NumUtil.keepStr(Double.parseDouble(empty.getLastValue().replace("MB", "")) / 1024, 1) + "GB";
|
||||||
String hostName = items.get(MonitorConstant.ITEM_HOSTNAME).getLastValue();
|
|
||||||
String osVersion = items.get(MonitorConstant.ITEM_OSVERSION).getLastValue();
|
empty = items.get(MonitorConstant.ITEM_CPUCORES);
|
||||||
String netWork = items.get(MonitorConstant.ITEM_NETWORK).getLastValue();
|
String cpuCores = ObjectUtil.isNull(empty) ? "--" : empty.getLastValue();
|
||||||
String location = items.get(MonitorConstant.ITEM_LOCATION).getLastValue();
|
|
||||||
String ip = items.get(MonitorConstant.ITEM_IP).getLastValue();
|
empty = items.get(MonitorConstant.ITEM_TOTALSIDKPAR);
|
||||||
String zone = items.get(MonitorConstant.ITEM_ZONE).getLastValue();
|
String totalDiskPar = ObjectUtil.isNull(empty) ? "--" : empty.getLastValue();
|
||||||
String osName = items.get(MonitorConstant.ITEM_OSNAME).getLastValue();
|
|
||||||
String startTime = items.get(MonitorConstant.ITEM_STARTTIME).getLastValue();
|
empty = items.get(MonitorConstant.ITEM_HOSTNAME);
|
||||||
String cpuType = items.get(MonitorConstant.ITEM_CPUTYPE).getLastValue();
|
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 */
|
/* 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);
|
Double cpuUsedValue = NumUtil.keep(cpuUsed, 3);
|
||||||
cpuUsedValue = ObjectUtil.isNull(cpuUsedValue) ? 0 : cpuUsedValue * 100;
|
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);
|
Double memoryUsedValue = NumUtil.keep(memoryUsed, 1);
|
||||||
memoryUsedValue = ObjectUtil.isNull(memoryUsedValue) ? 0 : memoryUsedValue;
|
memoryUsedValue = ObjectUtil.isNull(memoryUsedValue) ? 0 : memoryUsedValue;
|
||||||
|
|
||||||
Map<String, String> diskUsedMap = items.entrySet().stream() // 6.540206
|
Map<String, String> diskUsedMap = items.entrySet().stream() // 6.540206
|
||||||
.filter(entry -> entry.getKey().contains(MonitorConstant.PRIFIX_DISKUSED))
|
.filter(entry -> entry.getKey().contains(MonitorConstant.PRIFIX_DISKUSED))
|
||||||
.collect(Collectors.toMap(Map.Entry::getKey, item -> item.getValue().getLastValue()));
|
.collect(Collectors.toMap(Map.Entry::getKey, item -> item.getValue().getLastValue()));
|
||||||
|
@ -320,6 +345,7 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Scheduled(fixedDelay = 60, timeUnit = TimeUnit.SECONDS)
|
||||||
public void status2Redis() {
|
public void status2Redis() {
|
||||||
List<SysServer> sysServers = this.list();
|
List<SysServer> sysServers = this.list();
|
||||||
String key = RedisConstant.SERVER_STATUS;
|
String key = RedisConstant.SERVER_STATUS;
|
||||||
|
|
|
@ -3,9 +3,6 @@ package org.jeecg;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.jeecg.common.util.oConvertUtils;
|
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.CommandLineRunner;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
@ -28,12 +25,6 @@ import java.net.UnknownHostException;
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class JeecgAbnormalAlarmApplication extends SpringBootServletInitializer implements CommandLineRunner {
|
public class JeecgAbnormalAlarmApplication extends SpringBootServletInitializer implements CommandLineRunner {
|
||||||
|
|
||||||
private final ServerStatusManager serverStatusManager;
|
|
||||||
|
|
||||||
private final EmailStatusManager emailStatusManager;
|
|
||||||
|
|
||||||
private final DatabaseStatusManager databaseStatusManager;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||||
return application.sources(JeecgAbnormalAlarmApplication.class);
|
return application.sources(JeecgAbnormalAlarmApplication.class);
|
||||||
|
@ -54,12 +45,5 @@ public class JeecgAbnormalAlarmApplication extends SpringBootServletInitializer
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(String... args) throws Exception {
|
public void run(String... args) throws Exception {}
|
||||||
// 启动监测数据库连接状态的线程
|
|
||||||
databaseStatusManager.start();
|
|
||||||
// 启动监测邮箱服务器连接状态的线程
|
|
||||||
emailStatusManager.start();
|
|
||||||
// 启动监测服务器连接状态的线程
|
|
||||||
serverStatusManager.start();
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user