Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e58137c319 | ||
|
|
6bae49ee3b | ||
|
|
110932509a | ||
|
|
394e6b807c | ||
|
|
26daf92261 | ||
|
|
da16318bf5 | ||
|
|
321235fc23 | ||
|
|
179e29d9a5 | ||
|
|
72626c2b69 | ||
|
|
6c098b3950 |
@@ -60,6 +60,7 @@ public class AgentEndpoint {
|
|||||||
}
|
}
|
||||||
if(jsonObject.containsKey("netOID")){
|
if(jsonObject.containsKey("netOID")){
|
||||||
String netOID = jsonObject.getString("netOID");
|
String netOID = jsonObject.getString("netOID");
|
||||||
|
if(StringUtils.isNotBlank(netOID)){
|
||||||
LinkedHashMap<String, String> map = JSON.parseObject(netOID, new TypeReference<LinkedHashMap<String, String>>() {});
|
LinkedHashMap<String, String> map = JSON.parseObject(netOID, new TypeReference<LinkedHashMap<String, String>>() {});
|
||||||
GlobalConfig.SWITCH_NET_OID = map;
|
GlobalConfig.SWITCH_NET_OID = map;
|
||||||
LinkedHashMap<String,String> m = AgentUtil.swapMap(map);
|
LinkedHashMap<String,String> m = AgentUtil.swapMap(map);
|
||||||
@@ -67,8 +68,10 @@ public class AgentEndpoint {
|
|||||||
GlobalConfig.NET_INDEX_OID = m.get(GlobalConfig.NET_INDEX_PARAM);
|
GlobalConfig.NET_INDEX_OID = m.get(GlobalConfig.NET_INDEX_PARAM);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if(jsonObject.containsKey("moduleOID")){
|
if(jsonObject.containsKey("moduleOID")){
|
||||||
String moduleOID = jsonObject.getString("moduleOID");
|
String moduleOID = jsonObject.getString("moduleOID");
|
||||||
|
if(StringUtils.isNotBlank(moduleOID)){
|
||||||
LinkedHashMap<String, String> map = JSON.parseObject(moduleOID, new TypeReference<LinkedHashMap<String, String>>() {});
|
LinkedHashMap<String, String> map = JSON.parseObject(moduleOID, new TypeReference<LinkedHashMap<String, String>>() {});
|
||||||
GlobalConfig.SWITCH_MODULE_OID = map;
|
GlobalConfig.SWITCH_MODULE_OID = map;
|
||||||
LinkedHashMap<String,String> m = AgentUtil.swapMap(map);
|
LinkedHashMap<String,String> m = AgentUtil.swapMap(map);
|
||||||
@@ -76,8 +79,11 @@ public class AgentEndpoint {
|
|||||||
GlobalConfig.MODULE_INDEX_OID = m.get(GlobalConfig.MODULE_INDEX_PARAM);
|
GlobalConfig.MODULE_INDEX_OID = m.get(GlobalConfig.MODULE_INDEX_PARAM);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
if(jsonObject.containsKey("mpuOID")){
|
if(jsonObject.containsKey("mpuOID")){
|
||||||
String mpuOID = jsonObject.getString("mpuOID");
|
String mpuOID = jsonObject.getString("mpuOID");
|
||||||
|
if(StringUtils.isNotBlank(mpuOID)){
|
||||||
LinkedHashMap<String, String> map = JSON.parseObject(mpuOID, new TypeReference<LinkedHashMap<String, String>>() {});
|
LinkedHashMap<String, String> map = JSON.parseObject(mpuOID, new TypeReference<LinkedHashMap<String, String>>() {});
|
||||||
GlobalConfig.SWITCH_MPU_OID = map;
|
GlobalConfig.SWITCH_MPU_OID = map;
|
||||||
LinkedHashMap<String,String> m = AgentUtil.swapMap(map);
|
LinkedHashMap<String,String> m = AgentUtil.swapMap(map);
|
||||||
@@ -85,8 +91,10 @@ public class AgentEndpoint {
|
|||||||
GlobalConfig.MPU_INDEX_OID = m.get(GlobalConfig.MPU_INDEX_PARAM);
|
GlobalConfig.MPU_INDEX_OID = m.get(GlobalConfig.MPU_INDEX_PARAM);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if(jsonObject.containsKey("pwrOID")){
|
if(jsonObject.containsKey("pwrOID")){
|
||||||
String pwrOID = jsonObject.getString("pwrOID");
|
String pwrOID = jsonObject.getString("pwrOID");
|
||||||
|
if(StringUtils.isNotBlank(pwrOID)){
|
||||||
LinkedHashMap<String, String> map = JSON.parseObject(pwrOID, new TypeReference<LinkedHashMap<String, String>>() {});
|
LinkedHashMap<String, String> map = JSON.parseObject(pwrOID, new TypeReference<LinkedHashMap<String, String>>() {});
|
||||||
GlobalConfig.SWITCH_PWR_OID = map;
|
GlobalConfig.SWITCH_PWR_OID = map;
|
||||||
LinkedHashMap<String,String> m = AgentUtil.swapMap(map);
|
LinkedHashMap<String,String> m = AgentUtil.swapMap(map);
|
||||||
@@ -94,8 +102,10 @@ public class AgentEndpoint {
|
|||||||
GlobalConfig.PWR_INDEX_OID = m.get(GlobalConfig.PWR_INDEX_PARAM);
|
GlobalConfig.PWR_INDEX_OID = m.get(GlobalConfig.PWR_INDEX_PARAM);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if(jsonObject.containsKey("fanOID")){
|
if(jsonObject.containsKey("fanOID")){
|
||||||
String fanOID = jsonObject.getString("fanOID");
|
String fanOID = jsonObject.getString("fanOID");
|
||||||
|
if(StringUtils.isNotBlank(fanOID)){
|
||||||
LinkedHashMap<String, String> map = JSON.parseObject(fanOID, new TypeReference<LinkedHashMap<String, String>>() {});
|
LinkedHashMap<String, String> map = JSON.parseObject(fanOID, new TypeReference<LinkedHashMap<String, String>>() {});
|
||||||
GlobalConfig.SWITCH_FAN_OID = map;
|
GlobalConfig.SWITCH_FAN_OID = map;
|
||||||
LinkedHashMap<String,String> m = AgentUtil.swapMap(map);
|
LinkedHashMap<String,String> m = AgentUtil.swapMap(map);
|
||||||
@@ -103,8 +113,10 @@ public class AgentEndpoint {
|
|||||||
GlobalConfig.FAN_INDEX_OID = m.get(GlobalConfig.FAN_INDEX_PARAM);
|
GlobalConfig.FAN_INDEX_OID = m.get(GlobalConfig.FAN_INDEX_PARAM);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if(jsonObject.containsKey("otherOID")){
|
if(jsonObject.containsKey("otherOID")){
|
||||||
String otherOID = jsonObject.getString("otherOID");
|
String otherOID = jsonObject.getString("otherOID");
|
||||||
|
if(StringUtils.isNotBlank(otherOID)){
|
||||||
LinkedHashMap<String, String> map = JSON.parseObject(otherOID, new TypeReference<LinkedHashMap<String, String>>() {});
|
LinkedHashMap<String, String> map = JSON.parseObject(otherOID, new TypeReference<LinkedHashMap<String, String>>() {});
|
||||||
GlobalConfig.SWITCH_OTHER_OID = map;
|
GlobalConfig.SWITCH_OTHER_OID = map;
|
||||||
LinkedHashMap<String,String> m = AgentUtil.swapMap(map);
|
LinkedHashMap<String,String> m = AgentUtil.swapMap(map);
|
||||||
@@ -112,41 +124,54 @@ public class AgentEndpoint {
|
|||||||
GlobalConfig.OTHER_INDEX_OID = m.get(GlobalConfig.OTHER_INDEX_PARAM);
|
GlobalConfig.OTHER_INDEX_OID = m.get(GlobalConfig.OTHER_INDEX_PARAM);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if(jsonObject.containsKey("filters")){
|
if(jsonObject.containsKey("filters")){
|
||||||
String filters = jsonObject.getString("filters");
|
String filters = jsonObject.getString("filters");
|
||||||
|
if(StringUtils.isNotBlank(filters)){
|
||||||
JSONObject object = JSONObject.parseObject(filters);
|
JSONObject object = JSONObject.parseObject(filters);
|
||||||
|
|
||||||
if(object.containsKey("netOID")){
|
if(object.containsKey("netOID")){
|
||||||
String netOID = object.getString("netOID");
|
String netOID = object.getString("netOID");
|
||||||
|
if(StringUtils.isNotBlank(netOID)){
|
||||||
List<String> list = JSON.parseObject(netOID, new TypeReference<List<String>>() {});
|
List<String> list = JSON.parseObject(netOID, new TypeReference<List<String>>() {});
|
||||||
GlobalConfig.NET_FILTER = list;
|
GlobalConfig.NET_FILTER = list;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if(object.containsKey("moduleOID")){
|
if(object.containsKey("moduleOID")){
|
||||||
String moduleOID = object.getString("moduleOID");
|
String moduleOID = object.getString("moduleOID");
|
||||||
|
if(StringUtils.isNotBlank(moduleOID)){
|
||||||
List<String> list = JSON.parseObject(moduleOID, new TypeReference<List<String>>() {});
|
List<String> list = JSON.parseObject(moduleOID, new TypeReference<List<String>>() {});
|
||||||
GlobalConfig.MODULE_FILTER = list;
|
GlobalConfig.MODULE_FILTER = list;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if(object.containsKey("mpuOID")){
|
if(object.containsKey("mpuOID")){
|
||||||
String mpuOID = object.getString("mpuOID");
|
String mpuOID = object.getString("mpuOID");
|
||||||
|
if(StringUtils.isNotBlank(mpuOID)){
|
||||||
List<String> list = JSON.parseObject(mpuOID, new TypeReference<List<String>>() {});
|
List<String> list = JSON.parseObject(mpuOID, new TypeReference<List<String>>() {});
|
||||||
GlobalConfig.MPU_FILTER = list;
|
GlobalConfig.MPU_FILTER = list;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if(object.containsKey("pwrOID")){
|
if(object.containsKey("pwrOID")){
|
||||||
String pwrOID = object.getString("pwrOID");
|
String pwrOID = object.getString("pwrOID");
|
||||||
|
if(StringUtils.isNotBlank(pwrOID)){
|
||||||
List<String> list = JSON.parseObject(pwrOID, new TypeReference<List<String>>() {});
|
List<String> list = JSON.parseObject(pwrOID, new TypeReference<List<String>>() {});
|
||||||
GlobalConfig.PWR_FILTER = list;
|
GlobalConfig.PWR_FILTER = list;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if(object.containsKey("fanOID")){
|
if(object.containsKey("fanOID")){
|
||||||
String fanOID = object.getString("fanOID");
|
String fanOID = object.getString("fanOID");
|
||||||
|
if(StringUtils.isNotBlank(fanOID)){
|
||||||
List<String> list = JSON.parseObject(fanOID, new TypeReference<List<String>>() {});
|
List<String> list = JSON.parseObject(fanOID, new TypeReference<List<String>>() {});
|
||||||
GlobalConfig.FAN_FILTER = list;
|
GlobalConfig.FAN_FILTER = list;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if(object.containsKey("otherOID")){
|
if(object.containsKey("otherOID")){
|
||||||
String otherOID = object.getString("otherOID");
|
String otherOID = object.getString("otherOID");
|
||||||
|
if(StringUtils.isNotBlank(otherOID)){
|
||||||
List<String> list = JSON.parseObject(otherOID, new TypeReference<List<String>>() {});
|
List<String> list = JSON.parseObject(otherOID, new TypeReference<List<String>>() {});
|
||||||
GlobalConfig.OTHER_FILTER = list;
|
GlobalConfig.OTHER_FILTER = list;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -266,6 +291,7 @@ public class AgentEndpoint {
|
|||||||
JSONObject jsonObject = JSONObject.parseObject(data);
|
JSONObject jsonObject = JSONObject.parseObject(data);
|
||||||
if(jsonObject.containsKey("alarms")){
|
if(jsonObject.containsKey("alarms")){
|
||||||
String alarms = jsonObject.getString("alarms");
|
String alarms = jsonObject.getString("alarms");
|
||||||
|
if(StringUtils.isNotBlank(alarms)){
|
||||||
AssertLog.info("告警设置,alarms={}", alarms);
|
AssertLog.info("告警设置,alarms={}", alarms);
|
||||||
GlobalConfig.ALARM_LIST = JSON.parseObject(alarms, new TypeReference<List<AlarmEO>>() {});
|
GlobalConfig.ALARM_LIST = JSON.parseObject(alarms, new TypeReference<List<AlarmEO>>() {});
|
||||||
AssertLog.info("告警设置,监控项={}", JSON.toJSONString(GlobalConfig.ALARM_LIST));
|
AssertLog.info("告警设置,监控项={}", JSON.toJSONString(GlobalConfig.ALARM_LIST));
|
||||||
@@ -274,6 +300,7 @@ public class AgentEndpoint {
|
|||||||
GlobalConfig.IS_ALARM = AgentDataUtil.hasAnyActiveAlarm(GlobalConfig.ALARM_LIST);
|
GlobalConfig.IS_ALARM = AgentDataUtil.hasAnyActiveAlarm(GlobalConfig.ALARM_LIST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
agentService.alarmMonitor();
|
agentService.alarmMonitor();
|
||||||
long timestamp = System.currentTimeMillis();
|
long timestamp = System.currentTimeMillis();
|
||||||
timestamp = Math.round(timestamp / 1000.0);
|
timestamp = Math.round(timestamp / 1000.0);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.tongran.agent.client.netty.handler;
|
|||||||
import com.tongran.agent.client.core.config.GlobalConfig;
|
import com.tongran.agent.client.core.config.GlobalConfig;
|
||||||
import com.tongran.agent.client.core.session.SessionManager;
|
import com.tongran.agent.client.core.session.SessionManager;
|
||||||
import com.tongran.agent.client.scheduler.service.AppInitializer;
|
import com.tongran.agent.client.scheduler.service.AppInitializer;
|
||||||
|
import com.tongran.agent.client.service.AgentService;
|
||||||
import com.tongran.agent.client.utils.AssertLog;
|
import com.tongran.agent.client.utils.AssertLog;
|
||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelHandler;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
@@ -26,6 +27,9 @@ public class TCPListenHandler extends ChannelInboundHandlerAdapter {
|
|||||||
|
|
||||||
private final SessionManager sessionManager;
|
private final SessionManager sessionManager;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private AgentService agentService;
|
||||||
|
|
||||||
public TCPListenHandler() {
|
public TCPListenHandler() {
|
||||||
this.sessionManager = SessionManager.getInstance();
|
this.sessionManager = SessionManager.getInstance();
|
||||||
}
|
}
|
||||||
@@ -41,6 +45,7 @@ public class TCPListenHandler extends ChannelInboundHandlerAdapter {
|
|||||||
sessionManager.remove(ctx.channel());
|
sessionManager.remove(ctx.channel());
|
||||||
try {
|
try {
|
||||||
GlobalConfig.isCollect = false;
|
GlobalConfig.isCollect = false;
|
||||||
|
agentService.cancelCollect();
|
||||||
appInitializer.run();
|
appInitializer.run();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -51,6 +56,7 @@ public class TCPListenHandler extends ChannelInboundHandlerAdapter {
|
|||||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable e) {
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable e) {
|
||||||
if (e instanceof IOException) {
|
if (e instanceof IOException) {
|
||||||
AssertLog.info("<<<<<<[终端断开连接]{} {}", sessionManager.client(ctx), e.getMessage());
|
AssertLog.info("<<<<<<[终端断开连接]{} {}", sessionManager.client(ctx), e.getMessage());
|
||||||
|
agentService.cancelCollect();
|
||||||
} else {
|
} else {
|
||||||
AssertLog.info(">>>>>>[消息处理异常]" + sessionManager.client(ctx), e);
|
AssertLog.info(">>>>>>[消息处理异常]" + sessionManager.client(ctx), e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import org.springframework.context.annotation.Bean;
|
|||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.scheduling.annotation.EnableAsync;
|
import org.springframework.scheduling.annotation.EnableAsync;
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||||
|
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
@@ -16,7 +17,7 @@ public class SchedulerConfig {
|
|||||||
@Bean
|
@Bean
|
||||||
public ThreadPoolTaskScheduler taskScheduler() {
|
public ThreadPoolTaskScheduler taskScheduler() {
|
||||||
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
||||||
scheduler.setPoolSize(10); // 核心线程数
|
scheduler.setPoolSize(50); // 核心线程数
|
||||||
scheduler.setThreadNamePrefix("dynamic-scheduler-");
|
scheduler.setThreadNamePrefix("dynamic-scheduler-");
|
||||||
scheduler.setAwaitTerminationSeconds(60);
|
scheduler.setAwaitTerminationSeconds(60);
|
||||||
scheduler.setWaitForTasksToCompleteOnShutdown(true);
|
scheduler.setWaitForTasksToCompleteOnShutdown(true);
|
||||||
@@ -24,14 +25,31 @@ public class SchedulerConfig {
|
|||||||
scheduler.setRemoveOnCancelPolicy(true);
|
scheduler.setRemoveOnCancelPolicy(true);
|
||||||
return scheduler;
|
return scheduler;
|
||||||
}
|
}
|
||||||
|
// @Bean("taskExecutor")
|
||||||
|
// public ThreadPoolTaskScheduler taskExecutor() {
|
||||||
|
// ThreadPoolTaskScheduler executor = new ThreadPoolTaskScheduler();
|
||||||
|
// executor.setPoolSize(50); // 工作线程数
|
||||||
|
// executor.setThreadNamePrefix("task-worker-");
|
||||||
|
// executor.setAwaitTerminationSeconds(30);
|
||||||
|
// executor.setWaitForTasksToCompleteOnShutdown(true);
|
||||||
|
// return executor;
|
||||||
|
// }
|
||||||
|
|
||||||
@Bean("taskExecutor")
|
@Bean("taskExecutor")
|
||||||
public ThreadPoolTaskScheduler taskExecutor() {
|
public ThreadPoolTaskExecutor taskExecutor() {
|
||||||
ThreadPoolTaskScheduler executor = new ThreadPoolTaskScheduler();
|
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||||
executor.setPoolSize(11); // 工作线程数
|
// 核心配置
|
||||||
|
executor.setCorePoolSize(44);
|
||||||
|
executor.setMaxPoolSize(60);
|
||||||
|
executor.setQueueCapacity(100);
|
||||||
|
executor.setKeepAliveSeconds(60);
|
||||||
|
// 线程配置
|
||||||
executor.setThreadNamePrefix("task-worker-");
|
executor.setThreadNamePrefix("task-worker-");
|
||||||
executor.setAwaitTerminationSeconds(30);
|
executor.setAwaitTerminationSeconds(30);
|
||||||
executor.setWaitForTasksToCompleteOnShutdown(true);
|
executor.setWaitForTasksToCompleteOnShutdown(true);
|
||||||
|
// 拒绝策略
|
||||||
|
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||||
|
executor.initialize(); // 重要:必须调用initialize()
|
||||||
return executor;
|
return executor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -55,15 +55,24 @@ public class DynamicTaskService {
|
|||||||
lastExecutionTimes.put(taskId, startTime);
|
lastExecutionTimes.put(taskId, startTime);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
System.out.printf("开始执行任务: %s, 线程: %s%n",
|
||||||
|
taskId, Thread.currentThread().getName());
|
||||||
|
// 添加前置检查
|
||||||
|
if (originalTask == null) {
|
||||||
|
throw new IllegalArgumentException("原始任务不能为null");
|
||||||
|
}
|
||||||
originalTask.run();
|
originalTask.run();
|
||||||
|
System.out.printf("任务 %s 执行成功%n", taskId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("Task " + taskId + " execution failed: " + e.getMessage());
|
System.err.printf("任务 %s 执行失败: %s%n", taskId, e.getMessage());
|
||||||
|
// System.err.println("Task " + taskId + " execution failed: " + e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
long endTime = System.currentTimeMillis();
|
long endTime = System.currentTimeMillis();
|
||||||
long executionTime = endTime - startTime;
|
long executionTime = endTime - startTime;
|
||||||
taskExecutions.get(taskId).incrementAndGet();
|
taskExecutions.get(taskId).incrementAndGet();
|
||||||
|
// System.out.printf("Task %s executed in %dms, total executions: %d%n",
|
||||||
System.out.printf("Task %s executed in %dms, total executions: %d%n",
|
// taskId, executionTime, taskExecutions.get(taskId).get());
|
||||||
|
System.out.printf("任务 %s 执行耗时: %dms, 总执行次数: %d%n",
|
||||||
taskId, executionTime, taskExecutions.get(taskId).get());
|
taskId, executionTime, taskExecutions.get(taskId).get());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
+27
-29
@@ -1,19 +1,20 @@
|
|||||||
package com.tongran.agent.client.scheduler.task;
|
package com.tongran.agent.client.scheduler.task;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.tongran.agent.client.core.enums.MsgEnum;
|
import com.tongran.agent.client.core.enums.MsgEnum;
|
||||||
import com.tongran.agent.client.core.session.SessionManager;
|
import com.tongran.agent.client.core.session.SessionManager;
|
||||||
import com.tongran.agent.client.netty.model.Message;
|
import com.tongran.agent.client.netty.model.Message;
|
||||||
import com.tongran.agent.client.scheduler.service.AsyncCommandExecutor;
|
import com.tongran.agent.client.scheduler.service.AsyncCommandExecutor;
|
||||||
import com.tongran.agent.client.utils.AgentUtil;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.time.Instant;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@@ -72,10 +73,8 @@ public class SpecificTimeTaskService {
|
|||||||
// 实现你的业务逻辑
|
// 实现你的业务逻辑
|
||||||
try {
|
try {
|
||||||
System.out.println("处理业务: " + request.getTaskData());
|
System.out.println("处理业务: " + request.getTaskData());
|
||||||
|
String key = request.getTaskName()+"-"+System.currentTimeMillis();
|
||||||
List<Map<String,String>> list = new ArrayList<>();
|
|
||||||
for (String command : request.getTaskData()) {
|
for (String command : request.getTaskData()) {
|
||||||
Map<String,String> map = new HashMap<>();
|
|
||||||
if(StringUtils.equals(request.getDataType(), MsgEnum.Agent版本更新应答.getValue())){
|
if(StringUtils.equals(request.getDataType(), MsgEnum.Agent版本更新应答.getValue())){
|
||||||
try {
|
try {
|
||||||
System.out.println("重启进程已启动,当前服务退出");
|
System.out.println("重启进程已启动,当前服务退出");
|
||||||
@@ -94,35 +93,34 @@ public class SpecificTimeTaskService {
|
|||||||
cmd,
|
cmd,
|
||||||
100, TimeUnit.SECONDS);
|
100, TimeUnit.SECONDS);
|
||||||
future.thenAccept(result -> {
|
future.thenAccept(result -> {
|
||||||
if (result.isSuccess()) {
|
JSONObject jsonObject = new JSONObject();
|
||||||
System.out.println("脚本执行成功");
|
jsonObject.put("command", command);
|
||||||
System.out.println("[成功resOut] " + result.getOutput());
|
jsonObject.put("resOut", result.getOutput());
|
||||||
map.put("command",command);
|
System.out.println("JSON: " + jsonObject.toJSONString()); // 注意:toJSONString()
|
||||||
map.put("resOut",result.getOutput());
|
|
||||||
} else {
|
|
||||||
System.out.println("脚本执行失败");
|
|
||||||
System.out.println("[失败resOut] " + result.getOutput());
|
|
||||||
map.put("command",command);
|
|
||||||
map.put("resOut",result.getOutput());
|
|
||||||
}
|
|
||||||
}).exceptionally(ex -> {
|
|
||||||
System.err.println("执行失败: " + ex.getMessage());
|
|
||||||
map.put("command",command);
|
|
||||||
map.put("resOut","Policy execute filed");
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
list.add(map);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(CollectionUtil.isNotEmpty(list)){
|
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
json.put("resCode",1);
|
json.put("resCode",1);
|
||||||
json.put("resMsg", "");
|
json.put("resMsg", "");
|
||||||
json.put("result", AgentUtil.toJsonString(list));
|
json.put("result", jsonObject.toJSONString());
|
||||||
Message message = Message.builder().clientId(request.getClientId()).dataType(request.getDataType()).data(json.toString()).build();
|
json.put("timestamp", Instant.now().getEpochSecond());
|
||||||
|
Message message = Message.builder().clientId(request.getClientId()).dataType(request.getDataType()).data(json.toJSONString()).build();
|
||||||
|
if (Objects.nonNull(sessionManager.getSessionById(request.getClientId()))) {
|
||||||
|
System.out.println("发送执行结果: " + json.toJSONString()); // 注意:toJSONString()
|
||||||
|
sessionManager.writeAndFlush(sessionManager.getSessionById(request.getClientId()).getChannel(), message);
|
||||||
|
}
|
||||||
|
}).exceptionally(ex -> {
|
||||||
|
System.err.println("执行失败: " + ex.getMessage());
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("resCode",0);
|
||||||
|
json.put("resMsg", "执行失败:Policy execute filed");
|
||||||
|
json.put("result", "");
|
||||||
|
Message message = Message.builder().clientId(request.getClientId()).dataType(request.getDataType()).data(json.toJSONString()).build();
|
||||||
if (Objects.nonNull(sessionManager.getSessionById(request.getClientId()))) {
|
if (Objects.nonNull(sessionManager.getSessionById(request.getClientId()))) {
|
||||||
sessionManager.writeAndFlush(sessionManager.getSessionById(request.getClientId()).getChannel(), message);
|
sessionManager.writeAndFlush(sessionManager.getSessionById(request.getClientId()).getChannel(), message);
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 调用其他服务等
|
// 调用其他服务等
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ public class AgentServiceImpl implements AgentService {
|
|||||||
if(GlobalConfig.netCollect != collect || GlobalConfig.netInterval != interval){
|
if(GlobalConfig.netCollect != collect || GlobalConfig.netInterval != interval){
|
||||||
GlobalConfig.netCollect = collect;
|
GlobalConfig.netCollect = collect;
|
||||||
if(collect){
|
if(collect){
|
||||||
GlobalConfig.netInterval = interval;
|
// GlobalConfig.netInterval = interval;
|
||||||
long milli = AgentUtil.millisecondsToNext5Minute();
|
long milli = AgentUtil.millisecondsToNext5Minute();
|
||||||
dynamicTaskService.scheduleTask(type,
|
dynamicTaskService.scheduleTask(type,
|
||||||
businessTasks::netTask, milli, GlobalConfig.netInterval*1000L);
|
businessTasks::netTask, milli, GlobalConfig.netInterval*1000L);
|
||||||
@@ -144,186 +144,240 @@ public class AgentServiceImpl implements AgentService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default: //系统其他采集
|
case "systemSwapSizeFreeCollect": //交换卷/文件的可用空间(字节)采集
|
||||||
boolean flag = false;
|
|
||||||
if(StringUtils.equals(type, "systemSwapSizeFreeCollect")){
|
|
||||||
if(GlobalConfig.systemSwapSizeFreeCollect != collect || GlobalConfig.systemSwapSizeFreeInterval != interval){
|
if(GlobalConfig.systemSwapSizeFreeCollect != collect || GlobalConfig.systemSwapSizeFreeInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.systemSwapSizeFreeCollect = collect;
|
GlobalConfig.systemSwapSizeFreeCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.systemSwapSizeFreeInterval = interval;
|
GlobalConfig.systemSwapSizeFreeInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::systemSwapSizeFreeTask, milli, GlobalConfig.systemSwapSizeFreeInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.systemSwapSizeFreeInterval = 300;
|
GlobalConfig.systemSwapSizeFreeInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
if(StringUtils.equals(type, "memoryUtilizationCollect")){
|
case "memoryUtilizationCollect": //内存利用率采集
|
||||||
if(GlobalConfig.memoryUtilizationCollect != collect || GlobalConfig.memoryUtilizationInterval != interval){
|
if(GlobalConfig.memoryUtilizationCollect != collect || GlobalConfig.memoryUtilizationInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.memoryUtilizationCollect = collect;
|
GlobalConfig.memoryUtilizationCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.memoryUtilizationInterval = interval;
|
GlobalConfig.memoryUtilizationInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::memoryUtilizationTask, milli, GlobalConfig.memoryUtilizationInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.memoryUtilizationInterval = 300;
|
GlobalConfig.memoryUtilizationInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
if(StringUtils.equals(type, "systemSwapSizePercentCollect")){
|
case "systemSwapSizePercentCollect": //可用交换空间百分比采集
|
||||||
if(GlobalConfig.systemSwapSizePercentCollect != collect || GlobalConfig.systemSwapSizePercentInterval != interval){
|
if(GlobalConfig.systemSwapSizePercentCollect != collect || GlobalConfig.systemSwapSizePercentInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.systemSwapSizePercentCollect = collect;
|
GlobalConfig.systemSwapSizePercentCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.systemSwapSizePercentInterval = interval;
|
GlobalConfig.systemSwapSizePercentInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::systemSwapSizePercentTask, milli, GlobalConfig.systemSwapSizePercentInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.systemSwapSizePercentInterval = 300;
|
GlobalConfig.systemSwapSizePercentInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
if(StringUtils.equals(type, "memorySizeAvailableCollect")){
|
case "memorySizeAvailableCollect": //可用内存采集
|
||||||
if(GlobalConfig.memorySizeAvailableCollect != collect || GlobalConfig.memorySizeAvailableInterval != interval){
|
if(GlobalConfig.memorySizeAvailableCollect != collect || GlobalConfig.memorySizeAvailableInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.memorySizeAvailableCollect = collect;
|
GlobalConfig.memorySizeAvailableCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.memorySizeAvailableInterval = interval;
|
GlobalConfig.memorySizeAvailableInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::memorySizeAvailableTask, milli, GlobalConfig.memorySizeAvailableInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.memorySizeAvailableInterval = 300;
|
GlobalConfig.memorySizeAvailableInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
if(StringUtils.equals(type, "memorySizePercentCollect")){
|
case "memorySizePercentCollect": //可用内存百分比采集
|
||||||
if(GlobalConfig.memorySizePercentCollect != collect || GlobalConfig.memorySizePercentInterval != interval){
|
if(GlobalConfig.memorySizePercentCollect != collect || GlobalConfig.memorySizePercentInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.memorySizePercentCollect = collect;
|
GlobalConfig.memorySizePercentCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.memorySizePercentInterval = interval;
|
GlobalConfig.memorySizePercentInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::memorySizePercentTask, milli, GlobalConfig.memorySizePercentInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.memorySizePercentInterval = 300;
|
GlobalConfig.memorySizePercentInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
if(StringUtils.equals(type, "memorySizeTotalCollect")){
|
case "memorySizeTotalCollect": //总内存采集
|
||||||
if(GlobalConfig.memorySizeTotalCollect != collect || GlobalConfig.memorySizeTotalInterval != interval){
|
if(GlobalConfig.memorySizeTotalCollect != collect || GlobalConfig.memorySizeTotalInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.memorySizeTotalCollect = collect;
|
GlobalConfig.memorySizeTotalCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.memorySizeTotalInterval = interval;
|
GlobalConfig.memorySizeTotalInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::memorySizeTotalTask, milli, GlobalConfig.memorySizeTotalInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.memorySizeTotalInterval = 300;
|
GlobalConfig.memorySizeTotalInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
if(StringUtils.equals(type, "systemSwOsCollect")){
|
case "systemSwOsCollect": //操作系统采集
|
||||||
if(GlobalConfig.systemSwOsCollect != collect || GlobalConfig.systemSwOsInterval != interval){
|
if(GlobalConfig.systemSwOsCollect != collect || GlobalConfig.systemSwOsInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.systemSwOsCollect = collect;
|
GlobalConfig.systemSwOsCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.systemSwOsInterval = interval;
|
GlobalConfig.systemSwOsInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::systemSwOsTask, milli, GlobalConfig.systemSwOsInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.systemSwOsInterval = 300;
|
GlobalConfig.systemSwOsInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
if(StringUtils.equals(type, "systemSwArchCollect")){
|
case "systemSwArchCollect": //操作系统架构采集
|
||||||
if(GlobalConfig.systemSwArchCollect != collect || GlobalConfig.systemSwArchInterval != interval){
|
if(GlobalConfig.systemSwArchCollect != collect || GlobalConfig.systemSwArchInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.systemSwArchCollect = collect;
|
GlobalConfig.systemSwArchCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.systemSwArchInterval = interval;
|
GlobalConfig.systemSwArchInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::systemSwArchTask, milli, GlobalConfig.systemSwArchInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.systemSwArchInterval = 300;
|
GlobalConfig.systemSwArchInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
if(StringUtils.equals(type, "kernelMaxprocCollect")){
|
case "kernelMaxprocCollect": //最大进程数采集
|
||||||
if(GlobalConfig.kernelMaxprocCollect != collect || GlobalConfig.kernelMaxprocInterval != interval){
|
if(GlobalConfig.kernelMaxprocCollect != collect || GlobalConfig.kernelMaxprocInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.kernelMaxprocCollect = collect;
|
GlobalConfig.kernelMaxprocCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.kernelMaxprocInterval = interval;
|
GlobalConfig.kernelMaxprocInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::kernelMaxprocTask, milli, GlobalConfig.kernelMaxprocInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.kernelMaxprocInterval = 300;
|
GlobalConfig.kernelMaxprocInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
if(StringUtils.equals(type, "procNumRunCollect")){
|
case "procNumRunCollect": //正在运行的进程数采集
|
||||||
if(GlobalConfig.procNumRunCollect != collect || GlobalConfig.procNumRunInterval != interval){
|
if(GlobalConfig.procNumRunCollect != collect || GlobalConfig.procNumRunInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.procNumRunCollect = collect;
|
GlobalConfig.procNumRunCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.procNumRunInterval = interval;
|
GlobalConfig.procNumRunInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::procNumRunTask, milli, GlobalConfig.procNumRunInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.procNumRunInterval = 300;
|
GlobalConfig.procNumRunInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
if(StringUtils.equals(type, "systemUsersNumCollect")){
|
case "systemUsersNumCollect": //登录用户数采集
|
||||||
if(GlobalConfig.systemUsersNumCollect != collect || GlobalConfig.systemUsersNumInterval != interval){
|
if(GlobalConfig.systemUsersNumCollect != collect || GlobalConfig.systemUsersNumInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.systemUsersNumCollect = collect;
|
GlobalConfig.systemUsersNumCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.systemUsersNumInterval = interval;
|
GlobalConfig.systemUsersNumInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::systemUsersNumTask, milli, GlobalConfig.systemUsersNumInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.systemUsersNumInterval = 300;
|
GlobalConfig.systemUsersNumInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
if(StringUtils.equals(type, "systemDiskSizeTotalCollect")){
|
case "systemDiskSizeTotalCollect": //硬盘总可用空间采集
|
||||||
if(GlobalConfig.systemDiskSizeTotalCollect != collect || GlobalConfig.systemDiskSizeTotalInterval != interval){
|
if(GlobalConfig.systemDiskSizeTotalCollect != collect || GlobalConfig.systemDiskSizeTotalInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.systemDiskSizeTotalCollect = collect;
|
GlobalConfig.systemDiskSizeTotalCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.systemDiskSizeTotalInterval = interval;
|
GlobalConfig.systemDiskSizeTotalInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::systemDiskSizeTotalTask, milli, GlobalConfig.systemDiskSizeTotalInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.systemDiskSizeTotalInterval = 300;
|
GlobalConfig.systemDiskSizeTotalInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
if(StringUtils.equals(type, "systemBoottimeCollect")){
|
case "systemBoottimeCollect": //系统启动时间采集
|
||||||
if(GlobalConfig.systemBoottimeCollect != collect || GlobalConfig.systemBoottimeInterval != interval){
|
if(GlobalConfig.systemBoottimeCollect != collect || GlobalConfig.systemBoottimeInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.systemBoottimeCollect = collect;
|
GlobalConfig.systemBoottimeCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.systemBoottimeInterval = interval;
|
GlobalConfig.systemBoottimeInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::systemBoottimeTask, milli, GlobalConfig.systemBoottimeInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.systemBoottimeInterval = 300;
|
GlobalConfig.systemBoottimeInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
if(StringUtils.equals(type, "systemUnameCollect")){
|
case "systemUnameCollect": //系统描述采集
|
||||||
if(GlobalConfig.systemUnameCollect != collect || GlobalConfig.systemUnameInterval != interval){
|
if(GlobalConfig.systemUnameCollect != collect || GlobalConfig.systemUnameInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.systemUnameCollect = collect;
|
GlobalConfig.systemUnameCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.systemUnameInterval = interval;
|
GlobalConfig.systemUnameInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::systemUnameTask, milli, GlobalConfig.systemUnameInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.systemUnameInterval = 300;
|
GlobalConfig.systemUnameInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
if(StringUtils.equals(type, "systemLocaltimeCollect")){
|
case "systemLocaltimeCollect": //系统本地时间采集
|
||||||
if(GlobalConfig.systemLocaltimeCollect != collect || GlobalConfig.systemLocaltimeInterval != interval){
|
if(GlobalConfig.systemLocaltimeCollect != collect || GlobalConfig.systemLocaltimeInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.systemLocaltimeCollect = collect;
|
GlobalConfig.systemLocaltimeCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.systemLocaltimeInterval = interval;
|
GlobalConfig.systemLocaltimeInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::systemLocaltimeTask, milli, GlobalConfig.systemLocaltimeInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.systemLocaltimeInterval = 300;
|
GlobalConfig.systemLocaltimeInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
if(StringUtils.equals(type, "systemUptimeCollect")){
|
case "systemUptimeCollect": //系统正常运行时间采集
|
||||||
if(GlobalConfig.systemUptimeCollect != collect || GlobalConfig.systemUptimeInterval != interval){
|
if(GlobalConfig.systemUptimeCollect != collect || GlobalConfig.systemUptimeInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.systemUptimeCollect = collect;
|
GlobalConfig.systemUptimeCollect = collect;
|
||||||
GlobalConfig.systemUptimeInterval = c.getInterval();
|
if(collect){
|
||||||
if(!collect){
|
GlobalConfig.systemUptimeInterval = interval;
|
||||||
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::systemUptimeTask, milli, GlobalConfig.systemUptimeInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.systemUptimeInterval = 300;
|
GlobalConfig.systemUptimeInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
if(StringUtils.equals(type, "procNumCollect")){
|
default: //系统其他采集
|
||||||
if(GlobalConfig.procNumCollect != collect || GlobalConfig.procNumInterval != c.getInterval()){
|
|
||||||
flag = true;
|
|
||||||
GlobalConfig.procNumCollect = collect;
|
GlobalConfig.procNumCollect = collect;
|
||||||
GlobalConfig.procNumInterval = c.getInterval();
|
|
||||||
if(!collect){
|
|
||||||
GlobalConfig.procNumInterval = 300;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (flag) {
|
|
||||||
if(collect){
|
if(collect){
|
||||||
|
GlobalConfig.procNumInterval = interval;
|
||||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
dynamicTaskService.scheduleTask(type,
|
dynamicTaskService.scheduleTask(type,
|
||||||
() -> businessTasks.systemTask(type), milli, c.getInterval()*1000L);
|
businessTasks::procNumTask, milli, GlobalConfig.procNumInterval*1000L);
|
||||||
}else{
|
}else{
|
||||||
dynamicTaskService.cancelTask(type);
|
dynamicTaskService.cancelTask(type);
|
||||||
}
|
GlobalConfig.procNumInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -408,201 +462,268 @@ public class AgentServiceImpl implements AgentService {
|
|||||||
switch(type) {
|
switch(type) {
|
||||||
case "switchNetCollect": //交换机网络采集
|
case "switchNetCollect": //交换机网络采集
|
||||||
if(GlobalConfig.switchNetCollect != collect || GlobalConfig.switchNetInterval != interval){
|
if(GlobalConfig.switchNetCollect != collect || GlobalConfig.switchNetInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.switchNetCollect = collect;
|
GlobalConfig.switchNetCollect = collect;
|
||||||
GlobalConfig.switchNetInterval = interval;
|
if(collect){
|
||||||
if(!collect){
|
GlobalConfig.switchNetInterval = 300;
|
||||||
|
long milli = AgentUtil.millisecondsToNext5Minute();
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::switchNetTask, milli, GlobalConfig.switchNetInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.switchNetInterval = 300;
|
GlobalConfig.switchNetInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "switchModuleCollect": //光模块采集
|
case "switchModuleCollect": //光模块采集
|
||||||
if(GlobalConfig.switchModuleCollect != collect || GlobalConfig.switchModuleInterval != interval){
|
if(GlobalConfig.switchModuleCollect != collect || GlobalConfig.switchModuleInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.switchModuleCollect = collect;
|
GlobalConfig.switchModuleCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.switchModuleInterval = interval;
|
GlobalConfig.switchModuleInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::switchModuleTask, milli, GlobalConfig.switchModuleInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.switchModuleInterval = 300;
|
GlobalConfig.switchModuleInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "switchMpuCollect": //MPU采集
|
case "switchMpuCollect": //MPU采集
|
||||||
if(GlobalConfig.switchMpuCollect != collect || GlobalConfig.switchMpuInterval != interval){
|
if(GlobalConfig.switchMpuCollect != collect || GlobalConfig.switchMpuInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.switchMpuCollect = collect;
|
GlobalConfig.switchMpuCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.switchMpuInterval = interval;
|
GlobalConfig.switchMpuInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::switchMpuTask, milli, GlobalConfig.switchMpuInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.switchMpuInterval = 300;
|
GlobalConfig.switchMpuInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "switchPwrCollect": //电源采集
|
case "switchPwrCollect": //电源采集
|
||||||
if(GlobalConfig.switchPwrCollect != collect || GlobalConfig.switchPwrInterval != interval){
|
if(GlobalConfig.switchPwrCollect != collect || GlobalConfig.switchPwrInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.switchPwrCollect = collect;
|
GlobalConfig.switchPwrCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.switchPwrInterval = interval;
|
GlobalConfig.switchPwrInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::switchPwrTask, milli, GlobalConfig.switchPwrInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.switchPwrInterval = 300;
|
GlobalConfig.switchPwrInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "switchFanCollect": //风扇采集
|
case "switchFanCollect": //风扇采集
|
||||||
if(GlobalConfig.switchFanCollect != collect || GlobalConfig.switchFanInterval != interval){
|
if(GlobalConfig.switchFanCollect != collect || GlobalConfig.switchFanInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.switchFanCollect = collect;
|
GlobalConfig.switchFanCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.switchFanInterval = interval;
|
GlobalConfig.switchFanInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::switchFanTask, milli, GlobalConfig.switchFanInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.switchFanInterval = 300;
|
GlobalConfig.switchFanInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "switchSysDescrCollect":
|
case "switchSysDescrCollect":
|
||||||
if(GlobalConfig.switchSysDescrCollect != collect || GlobalConfig.switchSysDescrInterval != interval){
|
if(GlobalConfig.switchSysDescrCollect != collect || GlobalConfig.switchSysDescrInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.switchSysDescrCollect = collect;
|
GlobalConfig.switchSysDescrCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.switchSysDescrInterval = interval;
|
GlobalConfig.switchSysDescrInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::switchSysDescrTask, milli, GlobalConfig.switchSysDescrInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.switchSysDescrInterval = 300;
|
GlobalConfig.switchSysDescrInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "switchSysObjectIDCollect":
|
case "switchSysObjectIDCollect":
|
||||||
if(GlobalConfig.switchSysObjectIDCollect != collect || GlobalConfig.switchSysObjectIDInterval != interval){
|
if(GlobalConfig.switchSysObjectIDCollect != collect || GlobalConfig.switchSysObjectIDInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.switchSysObjectIDCollect = collect;
|
GlobalConfig.switchSysObjectIDCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.switchSysObjectIDInterval = interval;
|
GlobalConfig.switchSysObjectIDInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::switchSysObjectIDTask, milli, GlobalConfig.switchSysObjectIDInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.switchSysObjectIDInterval = 300;
|
GlobalConfig.switchSysObjectIDInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "switchSysUpTimeCollect":
|
case "switchSysUpTimeCollect":
|
||||||
if(GlobalConfig.switchSysUpTimeCollect != collect || GlobalConfig.switchSysUpTimeInterval != interval){
|
if(GlobalConfig.switchSysUpTimeCollect != collect || GlobalConfig.switchSysUpTimeInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.switchSysUpTimeCollect = collect;
|
GlobalConfig.switchSysUpTimeCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.switchSysUpTimeInterval = interval;
|
GlobalConfig.switchSysUpTimeInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::switchSysUpTimeTask, milli, GlobalConfig.switchSysUpTimeInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.switchSysUpTimeInterval = 300;
|
GlobalConfig.switchSysUpTimeInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "switchSysContactCollect":
|
case "switchSysContactCollect":
|
||||||
if(GlobalConfig.switchSysContactCollect != collect || GlobalConfig.switchSysContactInterval != interval){
|
if(GlobalConfig.switchSysContactCollect != collect || GlobalConfig.switchSysContactInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.switchSysContactCollect = collect;
|
GlobalConfig.switchSysContactCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.switchSysContactInterval = interval;
|
GlobalConfig.switchSysContactInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::switchSysContactTask, milli, GlobalConfig.switchSysContactInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.switchSysContactInterval = 300;
|
GlobalConfig.switchSysContactInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "switchSysNameCollect":
|
case "switchSysNameCollect":
|
||||||
if(GlobalConfig.switchSysNameCollect != collect || GlobalConfig.switchSysNameInterval != interval){
|
if(GlobalConfig.switchSysNameCollect != collect || GlobalConfig.switchSysNameInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.switchSysNameCollect = collect;
|
GlobalConfig.switchSysNameCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.switchSysNameInterval = interval;
|
GlobalConfig.switchSysNameInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::switchSysNameTask, milli, GlobalConfig.switchSysNameInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.switchSysNameInterval = 300;
|
GlobalConfig.switchSysNameInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "switchSysLocationCollect":
|
case "switchSysLocationCollect":
|
||||||
if(GlobalConfig.switchSysLocationCollect != collect || GlobalConfig.switchSysLocationInterval != interval){
|
if(GlobalConfig.switchSysLocationCollect != collect || GlobalConfig.switchSysLocationInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.switchSysLocationCollect = collect;
|
GlobalConfig.switchSysLocationCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.switchSysLocationInterval = interval;
|
GlobalConfig.switchSysLocationInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::switchSysLocationTask, milli, GlobalConfig.switchSysLocationInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.switchSysLocationInterval = 300;
|
GlobalConfig.switchSysLocationInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "switchHwStackSystemMacCollect":
|
case "switchHwStackSystemMacCollect":
|
||||||
if(GlobalConfig.switchHwStackSystemMacCollect != collect || GlobalConfig.switchHwStackSystemMacInterval != interval){
|
if(GlobalConfig.switchHwStackSystemMacCollect != collect || GlobalConfig.switchHwStackSystemMacInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.switchHwStackSystemMacCollect = collect;
|
GlobalConfig.switchHwStackSystemMacCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.switchHwStackSystemMacInterval = interval;
|
GlobalConfig.switchHwStackSystemMacInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::switchHwStackSystemMacTask, milli, GlobalConfig.switchHwStackSystemMacInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.switchHwStackSystemMacInterval = 300;
|
GlobalConfig.switchHwStackSystemMacInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "switchEntIndexCollect":
|
case "switchEntIndexCollect":
|
||||||
if(GlobalConfig.switchEntIndexCollect != collect || GlobalConfig.switchEntIndexInterval != interval){
|
if(GlobalConfig.switchEntIndexCollect != collect || GlobalConfig.switchEntIndexInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.switchEntIndexCollect = collect;
|
GlobalConfig.switchEntIndexCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.switchEntIndexInterval = interval;
|
GlobalConfig.switchEntIndexInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::switchEntIndexTask, milli, GlobalConfig.switchEntIndexInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.switchEntIndexInterval = 300;
|
GlobalConfig.switchEntIndexInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "switchEntPhysicalNameCollect":
|
case "switchEntPhysicalNameCollect":
|
||||||
if(GlobalConfig.switchEntPhysicalNameCollect != collect || GlobalConfig.switchEntPhysicalNameInterval != interval){
|
if(GlobalConfig.switchEntPhysicalNameCollect != collect || GlobalConfig.switchEntPhysicalNameInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.switchEntPhysicalNameCollect = collect;
|
GlobalConfig.switchEntPhysicalNameCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.switchEntPhysicalNameInterval = interval;
|
GlobalConfig.switchEntPhysicalNameInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::switchEntPhysicalNameTask, milli, GlobalConfig.switchEntPhysicalNameInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.switchEntPhysicalNameInterval = 300;
|
GlobalConfig.switchEntPhysicalNameInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "switchEntPhysicalSoftwareRevCollect":
|
case "switchEntPhysicalSoftwareRevCollect":
|
||||||
if(GlobalConfig.switchEntPhysicalSoftwareRevCollect != collect || GlobalConfig.switchEntPhysicalSoftwareRevInterval != interval){
|
if(GlobalConfig.switchEntPhysicalSoftwareRevCollect != collect || GlobalConfig.switchEntPhysicalSoftwareRevInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.switchEntPhysicalSoftwareRevCollect = collect;
|
GlobalConfig.switchEntPhysicalSoftwareRevCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.switchEntPhysicalSoftwareRevInterval = interval;
|
GlobalConfig.switchEntPhysicalSoftwareRevInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::switchEntPhysicalSoftwareRevTask, milli, GlobalConfig.switchEntPhysicalSoftwareRevInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.switchEntPhysicalSoftwareRevInterval = 300;
|
GlobalConfig.switchEntPhysicalSoftwareRevInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "switchHwEntityCpuUsageCollect":
|
case "switchHwEntityCpuUsageCollect":
|
||||||
if(GlobalConfig.switchHwEntityCpuUsageCollect != collect || GlobalConfig.switchHwEntityCpuUsageInterval != interval){
|
if(GlobalConfig.switchHwEntityCpuUsageCollect != collect || GlobalConfig.switchHwEntityCpuUsageInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.switchHwEntityCpuUsageCollect = collect;
|
GlobalConfig.switchHwEntityCpuUsageCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.switchHwEntityCpuUsageInterval = interval;
|
GlobalConfig.switchHwEntityCpuUsageInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::switchHwEntityCpuUsageTask, milli, GlobalConfig.switchHwEntityCpuUsageInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.switchHwEntityCpuUsageInterval = 300;
|
GlobalConfig.switchHwEntityCpuUsageInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "switchHwEntityMemUsageCollect":
|
case "switchHwEntityMemUsageCollect":
|
||||||
if(GlobalConfig.switchHwEntityMemUsageCollect != collect || GlobalConfig.switchHwEntityMemUsageInterval != interval){
|
if(GlobalConfig.switchHwEntityMemUsageCollect != collect || GlobalConfig.switchHwEntityMemUsageInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.switchHwEntityMemUsageCollect = collect;
|
GlobalConfig.switchHwEntityMemUsageCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.switchHwEntityMemUsageInterval = interval;
|
GlobalConfig.switchHwEntityMemUsageInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::switchHwEntityMemUsageTask, milli, GlobalConfig.switchHwEntityMemUsageInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.switchHwEntityMemUsageInterval = 300;
|
GlobalConfig.switchHwEntityMemUsageInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "switchHwAveragePowerCollect":
|
case "switchHwAveragePowerCollect":
|
||||||
if(GlobalConfig.switchHwAveragePowerCollect != collect || GlobalConfig.switchHwAveragePowerInterval != interval){
|
if(GlobalConfig.switchHwAveragePowerCollect != collect || GlobalConfig.switchHwAveragePowerInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.switchHwAveragePowerCollect = collect;
|
GlobalConfig.switchHwAveragePowerCollect = collect;
|
||||||
|
if(collect){
|
||||||
GlobalConfig.switchHwAveragePowerInterval = interval;
|
GlobalConfig.switchHwAveragePowerInterval = interval;
|
||||||
if(!collect){
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
|
dynamicTaskService.scheduleTask(type,
|
||||||
|
businessTasks::switchHwAveragePowerTask, milli, GlobalConfig.switchHwAveragePowerInterval*1000L);
|
||||||
|
}else{
|
||||||
|
dynamicTaskService.cancelTask(type);
|
||||||
GlobalConfig.switchHwAveragePowerInterval = 300;
|
GlobalConfig.switchHwAveragePowerInterval = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default: //系统其他采集
|
default: //系统其他采集
|
||||||
if(GlobalConfig.switchHwCurrentPowerCollect != collect || GlobalConfig.switchHwCurrentPowerInterval != interval){
|
if(GlobalConfig.switchHwCurrentPowerCollect != collect || GlobalConfig.switchHwCurrentPowerInterval != interval){
|
||||||
flag = true;
|
|
||||||
GlobalConfig.switchHwCurrentPowerCollect = collect;
|
GlobalConfig.switchHwCurrentPowerCollect = collect;
|
||||||
GlobalConfig.switchHwCurrentPowerInterval = interval;
|
|
||||||
if(!collect){
|
|
||||||
GlobalConfig.switchHwCurrentPowerInterval = 300;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (flag) {
|
|
||||||
if(collect){
|
if(collect){
|
||||||
long milli = AgentUtil.millisecondsToNext5Minute();
|
GlobalConfig.switchHwCurrentPowerInterval = interval;
|
||||||
|
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||||
dynamicTaskService.scheduleTask(type,
|
dynamicTaskService.scheduleTask(type,
|
||||||
() -> businessTasks.switchBoardTask(type), milli, interval*1000L);
|
businessTasks::switchHwCurrentPowerTask, milli, GlobalConfig.switchHwCurrentPowerInterval*1000L);
|
||||||
}else{
|
}else{
|
||||||
dynamicTaskService.cancelTask(type);
|
dynamicTaskService.cancelTask(type);
|
||||||
|
GlobalConfig.switchHwCurrentPowerInterval = 300;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -686,7 +807,7 @@ public class AgentServiceImpl implements AgentService {
|
|||||||
if(policy.getMethod() == 1){
|
if(policy.getMethod() == 1){
|
||||||
SpecificTimeRequest request = SpecificTimeRequest.builder()
|
SpecificTimeRequest request = SpecificTimeRequest.builder()
|
||||||
.taskId("")
|
.taskId("")
|
||||||
.taskName("")
|
.taskName(policy.getPolicyName())
|
||||||
.taskData(policy.getCommands())
|
.taskData(policy.getCommands())
|
||||||
.specificDateTime(AgentUtil.toLocalDateTime(policy.getPolicyTime(),true))
|
.specificDateTime(AgentUtil.toLocalDateTime(policy.getPolicyTime(),true))
|
||||||
.clientId(clientId)
|
.clientId(clientId)
|
||||||
|
|||||||
@@ -23,13 +23,14 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class SwitchBoardServiceImpl implements SwitchBoardService {
|
public class SwitchBoardServiceImpl implements SwitchBoardService {
|
||||||
@Override
|
@Override
|
||||||
public List<SwitchBoardVO> switchBoardList(long timestamp) {
|
public List<SwitchBoardVO> switchBoardList(long timestamp) {
|
||||||
List<SwitchBoardVO> list = new ArrayList<>();
|
List<SwitchBoardVO> list = new ArrayList<>();
|
||||||
System.out.println("==================== 交换机流量信息 ====================");
|
// System.out.println("==================== 交换机流量信息 ====================");
|
||||||
try {
|
try {
|
||||||
// 1. 创建传输映射
|
// 1. 创建传输映射
|
||||||
TransportMapping transport = new DefaultUdpTransportMapping();
|
TransportMapping transport = new DefaultUdpTransportMapping();
|
||||||
@@ -85,7 +86,7 @@ public class SwitchBoardServiceImpl implements SwitchBoardService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String handleSwitchNet(){
|
private String handleSwitchNet(){
|
||||||
System.out.println("==================== 交换机网络信息 ====================");
|
// System.out.println("==================== 交换机网络信息 ====================");
|
||||||
String result = "";
|
String result = "";
|
||||||
try {
|
try {
|
||||||
if(GlobalConfig.SWITCH_NET_OID.isEmpty()){
|
if(GlobalConfig.SWITCH_NET_OID.isEmpty()){
|
||||||
@@ -111,7 +112,7 @@ public class SwitchBoardServiceImpl implements SwitchBoardService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String handleSwitchModule(){
|
private String handleSwitchModule(){
|
||||||
System.out.println("==================== 交换机光模块信息 ====================");
|
// System.out.println("==================== 交换机光模块信息 ====================");
|
||||||
String result = "";
|
String result = "";
|
||||||
try {
|
try {
|
||||||
if(GlobalConfig.SWITCH_MODULE_OID.isEmpty()){
|
if(GlobalConfig.SWITCH_MODULE_OID.isEmpty()){
|
||||||
@@ -137,7 +138,7 @@ public class SwitchBoardServiceImpl implements SwitchBoardService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String handleSwitchMpu(){
|
private String handleSwitchMpu(){
|
||||||
System.out.println("==================== 交换机MPU信息 ====================");
|
// System.out.println("==================== 交换机MPU信息 ====================");
|
||||||
String result = "";
|
String result = "";
|
||||||
try {
|
try {
|
||||||
if(GlobalConfig.SWITCH_MPU_OID.isEmpty()){
|
if(GlobalConfig.SWITCH_MPU_OID.isEmpty()){
|
||||||
@@ -163,7 +164,7 @@ public class SwitchBoardServiceImpl implements SwitchBoardService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String handleSwitchPwr(){
|
private String handleSwitchPwr(){
|
||||||
System.out.println("==================== 交换机电源信息 ====================");
|
// System.out.println("==================== 交换机电源信息 ====================");
|
||||||
String result = "";
|
String result = "";
|
||||||
try {
|
try {
|
||||||
if(GlobalConfig.SWITCH_PWR_OID.isEmpty()){
|
if(GlobalConfig.SWITCH_PWR_OID.isEmpty()){
|
||||||
@@ -189,7 +190,7 @@ public class SwitchBoardServiceImpl implements SwitchBoardService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String handleSwitchFan(){
|
private String handleSwitchFan(){
|
||||||
System.out.println("==================== 交换机风扇信息 ====================");
|
// System.out.println("==================== 交换机风扇信息 ====================");
|
||||||
String result = "";
|
String result = "";
|
||||||
try {
|
try {
|
||||||
if(GlobalConfig.SWITCH_FAN_OID.isEmpty()){
|
if(GlobalConfig.SWITCH_FAN_OID.isEmpty()){
|
||||||
@@ -215,7 +216,7 @@ public class SwitchBoardServiceImpl implements SwitchBoardService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String handleSwitchOther(String type){
|
private String handleSwitchOther(String type){
|
||||||
System.out.println("==================== 交换机系统其他信息 ====================");
|
// System.out.println("==================== 交换机系统其他信息 ====================");
|
||||||
String result = "";
|
String result = "";
|
||||||
try {
|
try {
|
||||||
if(GlobalConfig.SWITCH_OTHER_OID.isEmpty()){
|
if(GlobalConfig.SWITCH_OTHER_OID.isEmpty()){
|
||||||
@@ -258,7 +259,7 @@ public class SwitchBoardServiceImpl implements SwitchBoardService {
|
|||||||
|
|
||||||
ResponseEvent event = snmp.send(pdu, target);
|
ResponseEvent event = snmp.send(pdu, target);
|
||||||
if (event != null && event.getResponse() != null) {
|
if (event != null && event.getResponse() != null) {
|
||||||
System.out.println("\n=== 交换机基本信息 ===");
|
// System.out.println("\n=== 交换机基本信息 ===");
|
||||||
for (VariableBinding vb : event.getResponse().getVariableBindings()) {
|
for (VariableBinding vb : event.getResponse().getVariableBindings()) {
|
||||||
System.out.printf("%-30s: %s%n",
|
System.out.printf("%-30s: %s%n",
|
||||||
getOIDDescription(vb.getOid().toString()),
|
getOIDDescription(vb.getOid().toString()),
|
||||||
@@ -404,6 +405,7 @@ public class SwitchBoardServiceImpl implements SwitchBoardService {
|
|||||||
ifNumberOID = GlobalConfig.OTHER_INDEX_OID;
|
ifNumberOID = GlobalConfig.OTHER_INDEX_OID;
|
||||||
filter_value = GlobalConfig.OTHER_FILTER;
|
filter_value = GlobalConfig.OTHER_FILTER;
|
||||||
}
|
}
|
||||||
|
AssertLog.info("交换机采集type={},筛选端口={}",type,JSON.toJSONString(filter_value));
|
||||||
if(StringUtils.isBlank(ifNumberOID)){
|
if(StringUtils.isBlank(ifNumberOID)){
|
||||||
System.err.println("未初始化索引OID");
|
System.err.println("未初始化索引OID");
|
||||||
return "";
|
return "";
|
||||||
@@ -437,19 +439,28 @@ public class SwitchBoardServiceImpl implements SwitchBoardService {
|
|||||||
}
|
}
|
||||||
// 提取最后一个值:就是 ifIndex 编号
|
// 提取最后一个值:就是 ifIndex 编号
|
||||||
int ifIndex = returnedOid.get(returnedOid.size() - 1);
|
int ifIndex = returnedOid.get(returnedOid.size() - 1);
|
||||||
// System.out.println("Found port index: " + ifIndex);
|
int value = vb.getVariable().toInt();
|
||||||
if(!filter_value.contains(String.valueOf(ifIndex))){
|
if(CollectionUtil.isEmpty(filter_value)){
|
||||||
|
// AssertLog.info("交换机采集type={},索引返回:值={}",type,vb);
|
||||||
indexes.add(ifIndex);
|
indexes.add(ifIndex);
|
||||||
|
}else{
|
||||||
|
if(filter_value.contains(String.valueOf(value))){
|
||||||
|
// AssertLog.info("交换机采集type={},索引返回:值={}",type,vb);
|
||||||
|
indexes.add(ifIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 更新下一次请求的起始 OID(SNMP Walk)
|
// 更新下一次请求的起始 OID(SNMP Walk)
|
||||||
pdu.set(0, new VariableBinding(responsePdu.getVariableBindings().get(0).getOid()));
|
pdu.set(0, new VariableBinding(responsePdu.getVariableBindings().get(0).getOid()));
|
||||||
}
|
}
|
||||||
System.out.println("\n=== 接口数量: " + indexes.size() + " ===");
|
|
||||||
if(CollectionUtil.isEmpty(indexes)){
|
if(CollectionUtil.isEmpty(indexes)){
|
||||||
System.err.println("返回获取索引列表为空");
|
System.err.println("返回获取索引列表为空");
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
//去重
|
||||||
|
indexes = indexes.stream().distinct().collect(Collectors.toList());
|
||||||
|
// System.out.println("\n=== 接口数量: " + indexes.size() + " ===");
|
||||||
|
// System.out.println("\n=== 接口列表: " + JSON.toJSONString(indexes));
|
||||||
String[] ifOIDs = oidParams.keySet().toArray(new String[0]);
|
String[] ifOIDs = oidParams.keySet().toArray(new String[0]);
|
||||||
String[] params = oidParams.values().toArray(new String[0]);
|
String[] params = oidParams.values().toArray(new String[0]);
|
||||||
if(!StringUtils.equals(type,"switchNet") && !StringUtils.equals(type,"switchModule")
|
if(!StringUtils.equals(type,"switchNet") && !StringUtils.equals(type,"switchModule")
|
||||||
@@ -514,7 +525,7 @@ public class SwitchBoardServiceImpl implements SwitchBoardService {
|
|||||||
if (event != null && event.getResponse() != null) {
|
if (event != null && event.getResponse() != null) {
|
||||||
VariableBinding[] vbs = event.getResponse().getVariableBindings().toArray(new VariableBinding[0]);
|
VariableBinding[] vbs = event.getResponse().getVariableBindings().toArray(new VariableBinding[0]);
|
||||||
for (int m = 0; m < params.length; m++) {
|
for (int m = 0; m < params.length; m++) {
|
||||||
AssertLog.info("参数名:{},值={}", params[m],vbs[m]);
|
// AssertLog.info("参数名:{},值={}", params[m],vbs[m]);
|
||||||
json.put(params[m],vbs[m].getVariable().toString());
|
json.put(params[m],vbs[m].getVariable().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -200,15 +200,14 @@ public class AgentUtil {
|
|||||||
|
|
||||||
public static long roundMinutes(){
|
public static long roundMinutes(){
|
||||||
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
// 四舍五入到最近的5分钟
|
int minute = now.getMinute();
|
||||||
LocalDateTime roundedTime = now
|
int roundedMinute = (int) (Math.round(minute / 5.0) * 5);
|
||||||
.truncatedTo(ChronoUnit.MINUTES) // 先去掉秒和纳秒
|
|
||||||
.withMinute((int) (Math.round(now.getMinute() / 5.0) * 5))
|
LocalDateTime roundedTime ;
|
||||||
.withSecond(0)
|
if (roundedMinute == 60) {
|
||||||
.withNano(0);
|
roundedTime = now.plusHours(1).withMinute(0).withSecond(0).withNano(0);
|
||||||
// 处理分钟进位的情况
|
} else {
|
||||||
if (roundedTime.getMinute() == 60) {
|
roundedTime = now.withMinute(roundedMinute).withSecond(0).withNano(0);
|
||||||
roundedTime = roundedTime.plusHours(1).withMinute(0);
|
|
||||||
}
|
}
|
||||||
// 转换为10位时间戳
|
// 转换为10位时间戳
|
||||||
long timestamp = roundedTime.atZone(ZoneId.systemDefault()).toEpochSecond();
|
long timestamp = roundedTime.atZone(ZoneId.systemDefault()).toEpochSecond();
|
||||||
|
|||||||
Reference in New Issue
Block a user