管道基础大数据平台系统开发-【后端】-Server
1
sws
2022-11-26 ab849f796bdc17236a95ea5fe5c166fb8f24a75c
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);
        }
    }
}