¶Ô±ÈÐÂÎļþ |
| | |
| | | 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); |
| | | } |
| | | } |
| | | } |