wvp-GB28181-pro/src/main/java/com/genersoft/iot/vmp/conf/SystemInfoTimerTask.java

40 lines
1.3 KiB
Java
Raw Normal View History

2022-02-04 21:46:48 +08:00
package com.genersoft.iot.vmp.conf;
2022-09-23 23:08:58 +08:00
import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.query.cmd.AlarmQueryMessageHandler;
2022-02-04 21:46:48 +08:00
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.utils.SystemInfoUtils;
2022-09-23 23:08:58 +08:00
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
2022-02-04 21:46:48 +08:00
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* redis
*/
@Component
public class SystemInfoTimerTask {
2022-09-23 23:08:58 +08:00
private Logger logger = LoggerFactory.getLogger(SystemInfoTimerTask.class);
2022-02-04 21:46:48 +08:00
@Autowired
private IRedisCatchStorage redisCatchStorage;
@Scheduled(fixedRate = 1000) //每1秒执行一次
public void execute(){
try {
double cpuInfo = SystemInfoUtils.getCpuInfo();
redisCatchStorage.addCpuInfo(cpuInfo);
double memInfo = SystemInfoUtils.getMemInfo();
redisCatchStorage.addMemInfo(memInfo);
Map<String, String> networkInterfaces = SystemInfoUtils.getNetworkInterfaces();
redisCatchStorage.addNetInfo(networkInterfaces);
} catch (InterruptedException e) {
2022-09-23 23:08:58 +08:00
logger.error("[获取系统信息失败] {}", e.getMessage());
2022-02-04 21:46:48 +08:00
}
}
}