管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2022-10-20 76e133d3c7db9cafdef4091ba755739fd2e63385
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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 = 15 * 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.getStackTrace());
        }
    }
 
    @Scheduled(fixedRate = 60 * 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.getStackTrace());
        }
    }
}