From ab849f796bdc17236a95ea5fe5c166fb8f24a75c Mon Sep 17 00:00:00 2001 From: sws <15810472099@163.com> Date: 星期六, 26 十一月 2022 16:12:02 +0800 Subject: [PATCH] 1 --- src/main/java/com/lf/server/config/ScheduleConfig.java | 86 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 86 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/lf/server/config/ScheduleConfig.java b/src/main/java/com/lf/server/config/ScheduleConfig.java new file mode 100644 index 0000000..e35b633 --- /dev/null +++ b/src/main/java/com/lf/server/config/ScheduleConfig.java @@ -0,0 +1,86 @@ +package com.lf.server.config; + +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.lf.server.service.all.ScheduleService; +import com.lf.server.service.all.WebSocketService; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +/** + * 鏃ョ▼閰嶇疆绫� + * @author WWW + */ +@Component +@EnableScheduling +public class ScheduleConfig { + @Autowired + private ScheduleService scheduleService; + + private static final Log log = LogFactory.getLog(ScheduleConfig.class); + + @Scheduled(fixedRate = 10 * 1000) + public void pushMonitorInfo() { + try { + JSONObject jsonObject = new JSONObject(); + + // 鏌ヨCpu淇℃伅 + jsonObject.put("cpuInfo", scheduleService.selectCpuInfo()); + // 鏌ヨ鍐呭瓨淇℃伅 + jsonObject.put("memInfo", scheduleService.selectMemInfo()); + // 鏌ヨ鍦ㄧ嚎鐢ㄦ埛 + jsonObject.put("userInfo", scheduleService.selectOnlineUsers()); + + String json = JSONObject.toJSONStringWithDateFormat(jsonObject, "yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteMapNullValue); + + WebSocketService.broadCastInfo(json); + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + } + } + + @Scheduled(fixedRate = 20 * 1000) + public void checkSystemStatus() { + try { + JSONObject jsonObject = new JSONObject(); + + // 鏌ヨ鏈嶅姟璧勬簮鐘舵�� + jsonObject.put("resInfo", scheduleService.selectResStatus()); + + String json = JSONObject.toJSONStringWithDateFormat(jsonObject, "yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteMapNullValue); + + WebSocketService.broadCastInfo(json); + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + } + } + + @Scheduled(fixedRate = 40 * 1000) + public void countSystemStatus() { + // noinspection AlibabaRemoveCommentedCode + try { + JSONObject jsonObject = new JSONObject(); + + // 鏈嶅姟璧勬簮鐘舵�� sys_res + jsonObject.put("resUseCount", scheduleService.countResStatus()); + + // 鐢ㄦ埛鐧诲綍鐘舵�� sys_login + jsonObject.put("userLoginCount", scheduleService.userLoginCount()); + + // 璧勬簮鎿嶄綔鐘舵�� sys_operate + jsonObject.put("operateCount", scheduleService.operateCount()); + + // 璧勬簮璋冪敤鐘舵�� + + String json = JSONObject.toJSONStringWithDateFormat(jsonObject, "yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteMapNullValue); + + WebSocketService.broadCastInfo(json); + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + } + } +} -- Gitblit v1.9.3