SystemInfoTimerTask.java 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package com.genersoft.iot.vmp.conf;
  2. import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.query.cmd.AlarmQueryMessageHandler;
  3. import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
  4. import com.genersoft.iot.vmp.utils.SystemInfoUtils;
  5. import org.slf4j.Logger;
  6. import org.slf4j.LoggerFactory;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.scheduling.annotation.Scheduled;
  9. import org.springframework.stereotype.Component;
  10. import java.util.List;
  11. import java.util.Map;
  12. /**
  13. * 获取系统信息写入redis
  14. */
  15. @Component
  16. public class SystemInfoTimerTask {
  17. private Logger logger = LoggerFactory.getLogger(SystemInfoTimerTask.class);
  18. @Autowired
  19. private IRedisCatchStorage redisCatchStorage;
  20. @Scheduled(fixedRate = 2000) //每1秒执行一次
  21. public void execute(){
  22. try {
  23. double cpuInfo = SystemInfoUtils.getCpuInfo();
  24. redisCatchStorage.addCpuInfo(cpuInfo);
  25. double memInfo = SystemInfoUtils.getMemInfo();
  26. redisCatchStorage.addMemInfo(memInfo);
  27. Map<String, Double> networkInterfaces = SystemInfoUtils.getNetworkInterfaces();
  28. redisCatchStorage.addNetInfo(networkInterfaces);
  29. List<Map<String, Object>> diskInfo =SystemInfoUtils.getDiskInfo();
  30. redisCatchStorage.addDiskInfo(diskInfo);
  31. } catch (InterruptedException e) {
  32. logger.error("[获取系统信息失败] {}", e.getMessage());
  33. }
  34. }
  35. }