线程池优化
This commit is contained in:
@@ -4,6 +4,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
@@ -24,14 +25,31 @@ public class SchedulerConfig {
|
||||
scheduler.setRemoveOnCancelPolicy(true);
|
||||
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")
|
||||
public ThreadPoolTaskScheduler taskExecutor() {
|
||||
ThreadPoolTaskScheduler executor = new ThreadPoolTaskScheduler();
|
||||
executor.setPoolSize(50); // 工作线程数
|
||||
public ThreadPoolTaskExecutor taskExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
// 核心配置
|
||||
executor.setCorePoolSize(44);
|
||||
executor.setMaxPoolSize(60);
|
||||
executor.setQueueCapacity(100);
|
||||
executor.setKeepAliveSeconds(60);
|
||||
// 线程配置
|
||||
executor.setThreadNamePrefix("task-worker-");
|
||||
executor.setAwaitTerminationSeconds(30);
|
||||
executor.setWaitForTasksToCompleteOnShutdown(true);
|
||||
// 拒绝策略
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
executor.initialize(); // 重要:必须调用initialize()
|
||||
return executor;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -55,16 +55,25 @@ public class DynamicTaskService {
|
||||
lastExecutionTimes.put(taskId, startTime);
|
||||
|
||||
try {
|
||||
System.out.printf("开始执行任务: %s, 线程: %s%n",
|
||||
taskId, Thread.currentThread().getName());
|
||||
// 添加前置检查
|
||||
if (originalTask == null) {
|
||||
throw new IllegalArgumentException("原始任务不能为null");
|
||||
}
|
||||
originalTask.run();
|
||||
System.out.printf("任务 %s 执行成功%n", taskId);
|
||||
} 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 {
|
||||
long endTime = System.currentTimeMillis();
|
||||
long executionTime = endTime - startTime;
|
||||
taskExecutions.get(taskId).incrementAndGet();
|
||||
|
||||
System.out.printf("Task %s executed in %dms, total executions: %d%n",
|
||||
taskId, executionTime, taskExecutions.get(taskId).get());
|
||||
// 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());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -144,187 +144,241 @@ public class AgentServiceImpl implements AgentService {
|
||||
}
|
||||
}
|
||||
break;
|
||||
default: //系统其他采集
|
||||
boolean flag = false;
|
||||
if(StringUtils.equals(type, "systemSwapSizeFreeCollect")){
|
||||
if(GlobalConfig.systemSwapSizeFreeCollect != collect || GlobalConfig.systemSwapSizeFreeInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.systemSwapSizeFreeCollect = collect;
|
||||
GlobalConfig.systemSwapSizeFreeInterval = interval;
|
||||
if(!collect){
|
||||
GlobalConfig.systemSwapSizeFreeInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "memoryUtilizationCollect")){
|
||||
if(GlobalConfig.memoryUtilizationCollect != collect || GlobalConfig.memoryUtilizationInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.memoryUtilizationCollect = collect;
|
||||
GlobalConfig.memoryUtilizationInterval = interval;
|
||||
if(!collect){
|
||||
GlobalConfig.memoryUtilizationInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "systemSwapSizePercentCollect")){
|
||||
if(GlobalConfig.systemSwapSizePercentCollect != collect || GlobalConfig.systemSwapSizePercentInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.systemSwapSizePercentCollect = collect;
|
||||
GlobalConfig.systemSwapSizePercentInterval = interval;
|
||||
if(!collect){
|
||||
GlobalConfig.systemSwapSizePercentInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "memorySizeAvailableCollect")){
|
||||
if(GlobalConfig.memorySizeAvailableCollect != collect || GlobalConfig.memorySizeAvailableInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.memorySizeAvailableCollect = collect;
|
||||
GlobalConfig.memorySizeAvailableInterval = interval;
|
||||
if(!collect){
|
||||
GlobalConfig.memorySizeAvailableInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "memorySizePercentCollect")){
|
||||
if(GlobalConfig.memorySizePercentCollect != collect || GlobalConfig.memorySizePercentInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.memorySizePercentCollect = collect;
|
||||
GlobalConfig.memorySizePercentInterval = interval;
|
||||
if(!collect){
|
||||
GlobalConfig.memorySizePercentInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "memorySizeTotalCollect")){
|
||||
if(GlobalConfig.memorySizeTotalCollect != collect || GlobalConfig.memorySizeTotalInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.memorySizeTotalCollect = collect;
|
||||
GlobalConfig.memorySizeTotalInterval = interval;
|
||||
if(!collect){
|
||||
GlobalConfig.memorySizeTotalInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "systemSwOsCollect")){
|
||||
if(GlobalConfig.systemSwOsCollect != collect || GlobalConfig.systemSwOsInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.systemSwOsCollect = collect;
|
||||
GlobalConfig.systemSwOsInterval = interval;
|
||||
if(!collect){
|
||||
GlobalConfig.systemSwOsInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "systemSwArchCollect")){
|
||||
if(GlobalConfig.systemSwArchCollect != collect || GlobalConfig.systemSwArchInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.systemSwArchCollect = collect;
|
||||
GlobalConfig.systemSwArchInterval = interval;
|
||||
if(!collect){
|
||||
GlobalConfig.systemSwArchInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "kernelMaxprocCollect")){
|
||||
if(GlobalConfig.kernelMaxprocCollect != collect || GlobalConfig.kernelMaxprocInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.kernelMaxprocCollect = collect;
|
||||
GlobalConfig.kernelMaxprocInterval = interval;
|
||||
if(!collect){
|
||||
GlobalConfig.kernelMaxprocInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "procNumRunCollect")){
|
||||
if(GlobalConfig.procNumRunCollect != collect || GlobalConfig.procNumRunInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.procNumRunCollect = collect;
|
||||
GlobalConfig.procNumRunInterval = interval;
|
||||
if(!collect){
|
||||
GlobalConfig.procNumRunInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "systemUsersNumCollect")){
|
||||
if(GlobalConfig.systemUsersNumCollect != collect || GlobalConfig.systemUsersNumInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.systemUsersNumCollect = collect;
|
||||
GlobalConfig.systemUsersNumInterval = interval;
|
||||
if(!collect){
|
||||
GlobalConfig.systemUsersNumInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "systemDiskSizeTotalCollect")){
|
||||
if(GlobalConfig.systemDiskSizeTotalCollect != collect || GlobalConfig.systemDiskSizeTotalInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.systemDiskSizeTotalCollect = collect;
|
||||
GlobalConfig.systemDiskSizeTotalInterval = interval;
|
||||
if(!collect){
|
||||
GlobalConfig.systemDiskSizeTotalInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "systemBoottimeCollect")){
|
||||
if(GlobalConfig.systemBoottimeCollect != collect || GlobalConfig.systemBoottimeInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.systemBoottimeCollect = collect;
|
||||
GlobalConfig.systemBoottimeInterval = interval;
|
||||
if(!collect){
|
||||
GlobalConfig.systemBoottimeInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "systemUnameCollect")){
|
||||
if(GlobalConfig.systemUnameCollect != collect || GlobalConfig.systemUnameInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.systemUnameCollect = collect;
|
||||
GlobalConfig.systemUnameInterval = interval;
|
||||
if(!collect){
|
||||
GlobalConfig.systemUnameInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "systemLocaltimeCollect")){
|
||||
if(GlobalConfig.systemLocaltimeCollect != collect || GlobalConfig.systemLocaltimeInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.systemLocaltimeCollect = collect;
|
||||
GlobalConfig.systemLocaltimeInterval = interval;
|
||||
if(!collect){
|
||||
GlobalConfig.systemLocaltimeInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "systemUptimeCollect")){
|
||||
if(GlobalConfig.systemUptimeCollect != collect || GlobalConfig.systemUptimeInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.systemUptimeCollect = collect;
|
||||
GlobalConfig.systemUptimeInterval = c.getInterval();
|
||||
if(!collect){
|
||||
GlobalConfig.systemUptimeInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "procNumCollect")){
|
||||
if(GlobalConfig.procNumCollect != collect || GlobalConfig.procNumInterval != c.getInterval()){
|
||||
flag = true;
|
||||
GlobalConfig.procNumCollect = collect;
|
||||
GlobalConfig.procNumInterval = c.getInterval();
|
||||
if(!collect){
|
||||
GlobalConfig.procNumInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
case "systemSwapSizeFreeCollect": //交换卷/文件的可用空间(字节)采集
|
||||
if(GlobalConfig.systemSwapSizeFreeCollect != collect || GlobalConfig.systemSwapSizeFreeInterval != interval){
|
||||
GlobalConfig.systemSwapSizeFreeCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.systemSwapSizeFreeInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
() -> businessTasks.systemTask(type), milli, c.getInterval()*1000L);
|
||||
businessTasks::systemSwapSizeFreeTask, milli, GlobalConfig.systemSwapSizeFreeInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.systemSwapSizeFreeInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "memoryUtilizationCollect": //内存利用率采集
|
||||
if(GlobalConfig.memoryUtilizationCollect != collect || GlobalConfig.memoryUtilizationInterval != interval){
|
||||
GlobalConfig.memoryUtilizationCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.memoryUtilizationInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::memoryUtilizationTask, milli, GlobalConfig.memoryUtilizationInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.memoryUtilizationInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "systemSwapSizePercentCollect": //可用交换空间百分比采集
|
||||
if(GlobalConfig.systemSwapSizePercentCollect != collect || GlobalConfig.systemSwapSizePercentInterval != interval){
|
||||
GlobalConfig.systemSwapSizePercentCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.systemSwapSizePercentInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::systemSwapSizePercentTask, milli, GlobalConfig.systemSwapSizePercentInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.systemSwapSizePercentInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "memorySizeAvailableCollect": //可用内存采集
|
||||
if(GlobalConfig.memorySizeAvailableCollect != collect || GlobalConfig.memorySizeAvailableInterval != interval){
|
||||
GlobalConfig.memorySizeAvailableCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.memorySizeAvailableInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::memorySizeAvailableTask, milli, GlobalConfig.memorySizeAvailableInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.memorySizeAvailableInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "memorySizePercentCollect": //可用内存百分比采集
|
||||
if(GlobalConfig.memorySizePercentCollect != collect || GlobalConfig.memorySizePercentInterval != interval){
|
||||
GlobalConfig.memorySizePercentCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.memorySizePercentInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::memorySizePercentTask, milli, GlobalConfig.memorySizePercentInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.memorySizePercentInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "memorySizeTotalCollect": //总内存采集
|
||||
if(GlobalConfig.memorySizeTotalCollect != collect || GlobalConfig.memorySizeTotalInterval != interval){
|
||||
GlobalConfig.memorySizeTotalCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.memorySizeTotalInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::memorySizeTotalTask, milli, GlobalConfig.memorySizeTotalInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.memorySizeTotalInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "systemSwOsCollect": //操作系统采集
|
||||
if(GlobalConfig.systemSwOsCollect != collect || GlobalConfig.systemSwOsInterval != interval){
|
||||
GlobalConfig.systemSwOsCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.systemSwOsInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::systemSwOsTask, milli, GlobalConfig.systemSwOsInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.systemSwOsInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "systemSwArchCollect": //操作系统架构采集
|
||||
if(GlobalConfig.systemSwArchCollect != collect || GlobalConfig.systemSwArchInterval != interval){
|
||||
GlobalConfig.systemSwArchCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.systemSwArchInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::systemSwArchTask, milli, GlobalConfig.systemSwArchInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.systemSwArchInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "kernelMaxprocCollect": //最大进程数采集
|
||||
if(GlobalConfig.kernelMaxprocCollect != collect || GlobalConfig.kernelMaxprocInterval != interval){
|
||||
GlobalConfig.kernelMaxprocCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.kernelMaxprocInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::kernelMaxprocTask, milli, GlobalConfig.kernelMaxprocInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.kernelMaxprocInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "procNumRunCollect": //正在运行的进程数采集
|
||||
if(GlobalConfig.procNumRunCollect != collect || GlobalConfig.procNumRunInterval != interval){
|
||||
GlobalConfig.procNumRunCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.procNumRunInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::procNumRunTask, milli, GlobalConfig.procNumRunInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.procNumRunInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "systemUsersNumCollect": //登录用户数采集
|
||||
if(GlobalConfig.systemUsersNumCollect != collect || GlobalConfig.systemUsersNumInterval != interval){
|
||||
GlobalConfig.systemUsersNumCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.systemUsersNumInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::systemUsersNumTask, milli, GlobalConfig.systemUsersNumInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.systemUsersNumInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "systemDiskSizeTotalCollect": //硬盘总可用空间采集
|
||||
if(GlobalConfig.systemDiskSizeTotalCollect != collect || GlobalConfig.systemDiskSizeTotalInterval != interval){
|
||||
GlobalConfig.systemDiskSizeTotalCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.systemDiskSizeTotalInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::systemDiskSizeTotalTask, milli, GlobalConfig.systemDiskSizeTotalInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.systemDiskSizeTotalInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "systemBoottimeCollect": //系统启动时间采集
|
||||
if(GlobalConfig.systemBoottimeCollect != collect || GlobalConfig.systemBoottimeInterval != interval){
|
||||
GlobalConfig.systemBoottimeCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.systemBoottimeInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::systemBoottimeTask, milli, GlobalConfig.systemBoottimeInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.systemBoottimeInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "systemUnameCollect": //系统描述采集
|
||||
if(GlobalConfig.systemUnameCollect != collect || GlobalConfig.systemUnameInterval != interval){
|
||||
GlobalConfig.systemUnameCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.systemUnameInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::systemUnameTask, milli, GlobalConfig.systemUnameInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.systemUnameInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "systemLocaltimeCollect": //系统本地时间采集
|
||||
if(GlobalConfig.systemLocaltimeCollect != collect || GlobalConfig.systemLocaltimeInterval != interval){
|
||||
GlobalConfig.systemLocaltimeCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.systemLocaltimeInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::systemLocaltimeTask, milli, GlobalConfig.systemLocaltimeInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.systemLocaltimeInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "systemUptimeCollect": //系统正常运行时间采集
|
||||
if(GlobalConfig.systemUptimeCollect != collect || GlobalConfig.systemUptimeInterval != interval){
|
||||
GlobalConfig.systemUptimeCollect = 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;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default: //系统其他采集
|
||||
GlobalConfig.procNumCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.procNumInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::procNumTask, milli, GlobalConfig.procNumInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.procNumInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -408,207 +462,270 @@ public class AgentServiceImpl implements AgentService {
|
||||
switch(type) {
|
||||
case "switchNetCollect": //交换机网络采集
|
||||
if(GlobalConfig.switchNetCollect != collect || GlobalConfig.switchNetInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchNetCollect = collect;
|
||||
// GlobalConfig.switchNetInterval = interval;
|
||||
// if(!collect){
|
||||
// GlobalConfig.switchNetInterval = 300;
|
||||
// }
|
||||
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;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchModuleCollect": //光模块采集
|
||||
if(GlobalConfig.switchModuleCollect != collect || GlobalConfig.switchModuleInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchModuleCollect = collect;
|
||||
GlobalConfig.switchModuleInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchModuleInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchModuleTask, milli, GlobalConfig.switchModuleInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchModuleInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchMpuCollect": //MPU采集
|
||||
if(GlobalConfig.switchMpuCollect != collect || GlobalConfig.switchMpuInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchMpuCollect = collect;
|
||||
GlobalConfig.switchMpuInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchMpuInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchMpuTask, milli, GlobalConfig.switchMpuInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchMpuInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchPwrCollect": //电源采集
|
||||
if(GlobalConfig.switchPwrCollect != collect || GlobalConfig.switchPwrInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchPwrCollect = collect;
|
||||
GlobalConfig.switchPwrInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchPwrInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchPwrTask, milli, GlobalConfig.switchPwrInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchPwrInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchFanCollect": //风扇采集
|
||||
if(GlobalConfig.switchFanCollect != collect || GlobalConfig.switchFanInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchFanCollect = collect;
|
||||
GlobalConfig.switchFanInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchFanInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchFanTask, milli, GlobalConfig.switchFanInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchFanInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchSysDescrCollect":
|
||||
if(GlobalConfig.switchSysDescrCollect != collect || GlobalConfig.switchSysDescrInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchSysDescrCollect = collect;
|
||||
GlobalConfig.switchSysDescrInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchSysDescrInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchSysDescrTask, milli, GlobalConfig.switchSysDescrInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchSysDescrInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchSysObjectIDCollect":
|
||||
if(GlobalConfig.switchSysObjectIDCollect != collect || GlobalConfig.switchSysObjectIDInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchSysObjectIDCollect = collect;
|
||||
GlobalConfig.switchSysObjectIDInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchSysObjectIDInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchSysObjectIDTask, milli, GlobalConfig.switchSysObjectIDInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchSysObjectIDInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchSysUpTimeCollect":
|
||||
if(GlobalConfig.switchSysUpTimeCollect != collect || GlobalConfig.switchSysUpTimeInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchSysUpTimeCollect = collect;
|
||||
GlobalConfig.switchSysUpTimeInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchSysUpTimeInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchSysUpTimeTask, milli, GlobalConfig.switchSysUpTimeInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchSysUpTimeInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchSysContactCollect":
|
||||
if(GlobalConfig.switchSysContactCollect != collect || GlobalConfig.switchSysContactInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchSysContactCollect = collect;
|
||||
GlobalConfig.switchSysContactInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchSysContactInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchSysContactTask, milli, GlobalConfig.switchSysContactInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchSysContactInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchSysNameCollect":
|
||||
if(GlobalConfig.switchSysNameCollect != collect || GlobalConfig.switchSysNameInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchSysNameCollect = collect;
|
||||
GlobalConfig.switchSysNameInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchSysNameInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchSysNameTask, milli, GlobalConfig.switchSysNameInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchSysNameInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchSysLocationCollect":
|
||||
if(GlobalConfig.switchSysLocationCollect != collect || GlobalConfig.switchSysLocationInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchSysLocationCollect = collect;
|
||||
GlobalConfig.switchSysLocationInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchSysLocationInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchSysLocationTask, milli, GlobalConfig.switchSysLocationInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchSysLocationInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchHwStackSystemMacCollect":
|
||||
if(GlobalConfig.switchHwStackSystemMacCollect != collect || GlobalConfig.switchHwStackSystemMacInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchHwStackSystemMacCollect = collect;
|
||||
GlobalConfig.switchHwStackSystemMacInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchHwStackSystemMacInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchHwStackSystemMacTask, milli, GlobalConfig.switchHwStackSystemMacInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchHwStackSystemMacInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchEntIndexCollect":
|
||||
if(GlobalConfig.switchEntIndexCollect != collect || GlobalConfig.switchEntIndexInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchEntIndexCollect = collect;
|
||||
GlobalConfig.switchEntIndexInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchEntIndexInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchEntIndexTask, milli, GlobalConfig.switchEntIndexInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchEntIndexInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchEntPhysicalNameCollect":
|
||||
if(GlobalConfig.switchEntPhysicalNameCollect != collect || GlobalConfig.switchEntPhysicalNameInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchEntPhysicalNameCollect = collect;
|
||||
GlobalConfig.switchEntPhysicalNameInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchEntPhysicalNameInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchEntPhysicalNameTask, milli, GlobalConfig.switchEntPhysicalNameInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchEntPhysicalNameInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchEntPhysicalSoftwareRevCollect":
|
||||
if(GlobalConfig.switchEntPhysicalSoftwareRevCollect != collect || GlobalConfig.switchEntPhysicalSoftwareRevInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchEntPhysicalSoftwareRevCollect = collect;
|
||||
GlobalConfig.switchEntPhysicalSoftwareRevInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchEntPhysicalSoftwareRevInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchEntPhysicalSoftwareRevTask, milli, GlobalConfig.switchEntPhysicalSoftwareRevInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchEntPhysicalSoftwareRevInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchHwEntityCpuUsageCollect":
|
||||
if(GlobalConfig.switchHwEntityCpuUsageCollect != collect || GlobalConfig.switchHwEntityCpuUsageInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchHwEntityCpuUsageCollect = collect;
|
||||
GlobalConfig.switchHwEntityCpuUsageInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchHwEntityCpuUsageInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchHwEntityCpuUsageTask, milli, GlobalConfig.switchHwEntityCpuUsageInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchHwEntityCpuUsageInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchHwEntityMemUsageCollect":
|
||||
if(GlobalConfig.switchHwEntityMemUsageCollect != collect || GlobalConfig.switchHwEntityMemUsageInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchHwEntityMemUsageCollect = collect;
|
||||
GlobalConfig.switchHwEntityMemUsageInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchHwEntityMemUsageInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchHwEntityMemUsageTask, milli, GlobalConfig.switchHwEntityMemUsageInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchHwEntityMemUsageInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchHwAveragePowerCollect":
|
||||
if(GlobalConfig.switchHwAveragePowerCollect != collect || GlobalConfig.switchHwAveragePowerInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchHwAveragePowerCollect = collect;
|
||||
GlobalConfig.switchHwAveragePowerInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchHwAveragePowerInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchHwAveragePowerTask, milli, GlobalConfig.switchHwAveragePowerInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchHwAveragePowerInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default: //系统其他采集
|
||||
if(GlobalConfig.switchHwCurrentPowerCollect != collect || GlobalConfig.switchHwCurrentPowerInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchHwCurrentPowerCollect = collect;
|
||||
GlobalConfig.switchHwCurrentPowerInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchHwCurrentPowerInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchHwCurrentPowerTask, milli, GlobalConfig.switchHwCurrentPowerInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchHwCurrentPowerInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
if(collect){
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
if(StringUtils.equals(type,"switchNetCollect")){
|
||||
milli = AgentUtil.millisecondsToNext5Minute();
|
||||
interval = 300;
|
||||
}
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
() -> businessTasks.switchBoardTask(type), milli, interval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user