package com.moon.server.config; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.serializer.SerializerFeature; import com.moon.server.entity.data.FmeLogEntity; import com.moon.server.service.all.ScheduleService; import com.moon.server.service.all.WebSocketService; import com.moon.server.service.sys.AttachService; 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; import java.util.List; @Component @EnableScheduling @SuppressWarnings("ALL") public class ScheduleConfig { @Autowired AttachService attachService; @Autowired ScheduleService scheduleService; private static boolean isBusy = false; private static final Log log = LogFactory.getLog(ScheduleConfig.class); @Scheduled(fixedRate = 15 * 1000) public void pushMonitorInfo() { try { JSONObject jsonObject = new JSONObject(); 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 = 30 * 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 = 30 * 1000) public void countSystemStatus() { // noinspection AlibabaRemoveCommentedCode try { JSONObject jsonObject = new JSONObject(); jsonObject.put("resUseCount", scheduleService.countResStatus()); jsonObject.put("userLoginCount", scheduleService.userLoginCount()); 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); } } }