[ agent ] [ status ] - accomplish agent status - 8
This commit is contained in:
@@ -6,6 +6,7 @@ import io.wdd.agent.config.beans.init.AgentServerInfo;
|
||||
import io.wdd.common.beans.status.*;
|
||||
import io.wdd.common.utils.TimeUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.redis.connection.stream.StreamRecords;
|
||||
import org.springframework.data.redis.connection.stream.StringRecord;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
@@ -15,6 +16,7 @@ import oshi.SystemInfo;
|
||||
import oshi.hardware.HardwareAbstractionLayer;
|
||||
import oshi.software.os.OperatingSystem;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -48,6 +50,11 @@ public class AgentStatusCollector {
|
||||
@Resource
|
||||
AgentServerInfo agentServerInfo;
|
||||
|
||||
|
||||
private static final long ReportInitDelay = 60000;
|
||||
private static final long ReportFixedRate = 15000;
|
||||
|
||||
|
||||
public AgentStatus collect() {
|
||||
|
||||
AgentStatus agentStatus = AgentStatusCache.get(0);
|
||||
@@ -99,7 +106,7 @@ public class AgentStatusCollector {
|
||||
|
||||
// agent boot up 120s then start to report its status
|
||||
// at the fix rate of 15s
|
||||
@Scheduled(initialDelay = 60000, fixedRate = 15000)
|
||||
@Scheduled(initialDelay = ReportInitDelay, fixedRate = ReportFixedRate)
|
||||
public void sendAgentStatusToRedis() {
|
||||
|
||||
try {
|
||||
|
||||
@@ -15,6 +15,7 @@ public class CpuInfo {
|
||||
|
||||
|
||||
private static final DecimalFormat LOAD_FORMAT = new DecimalFormat("#.00");
|
||||
private static final double GHZ_UNIT = 1000000000d;
|
||||
|
||||
/**
|
||||
* CPU总线程
|
||||
@@ -56,6 +57,10 @@ public class CpuInfo {
|
||||
*/
|
||||
private CpuModel cpuModel;
|
||||
|
||||
private double maxFreq;
|
||||
|
||||
private double[] runFreq;
|
||||
|
||||
private double[] cpuLoadAverage;
|
||||
|
||||
private double[] systemLoadAverage;
|
||||
@@ -94,6 +99,22 @@ public class CpuInfo {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static double formatCpuFrequency(long freq){
|
||||
|
||||
return Double.parseDouble(LOAD_FORMAT.format(freq / GHZ_UNIT));
|
||||
}
|
||||
|
||||
private static double[] formatCpuFrequencyList(long[] freqList){
|
||||
|
||||
int length = freqList.length;
|
||||
double[] result = new double[length];
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
result[i] = formatCpuFrequency(freqList[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定等待时间内系统CPU 系统使用率、用户使用率、利用率等等 相关信息
|
||||
*
|
||||
@@ -106,21 +127,26 @@ public class CpuInfo {
|
||||
final CpuTicks ticks = new CpuTicks(processor, waitingTime);
|
||||
//this.ticks = ticks;
|
||||
|
||||
// base core info
|
||||
this.cpuTotal = processor.getLogicalProcessorCount();
|
||||
this.coreTotal = processor.getPhysicalProcessorCount();
|
||||
|
||||
// cpu information
|
||||
this.cpuModel = mapFromProcessorIdentifier(processor.getProcessorIdentifier());
|
||||
|
||||
final long totalCpu = ticks.totalCpu();
|
||||
this.cpuUsageTotol = totalCpu;
|
||||
|
||||
// cpu frequency
|
||||
this.maxFreq = formatCpuFrequency(processor.getMaxFreq());
|
||||
this.runFreq = formatCpuFrequencyList(processor.getCurrentFreq());
|
||||
|
||||
// cpu usage
|
||||
this.systemCpuUsage = formatDouble(ticks.cSys, totalCpu);
|
||||
this.userCpuUsage = formatDouble(ticks.user, totalCpu);
|
||||
|
||||
this.wait = formatDouble(ticks.ioWait, totalCpu);
|
||||
this.free = formatDouble(ticks.idle, totalCpu);
|
||||
|
||||
|
||||
// system load average
|
||||
this.systemLoadAverage = processor.getSystemLoadAverage(3);
|
||||
|
||||
@@ -140,6 +166,8 @@ public class CpuInfo {
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* CPU型号信息
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user