Filter the NaN of system_cpu_usage/process_cpu_usage (#16289)

This commit is contained in:
Wenjun Ruan 2024-07-08 21:43:59 +08:00 committed by GitHub
parent 8f6df8d840
commit 255ec35c3b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -33,6 +33,9 @@ public class DefaultMetricsProvider implements MetricsProvider {
private long lastRefreshTime = 0;
private double lastSystemCpuUsage = 0.0d;
private double lastProcessCpuUsage = 0.0d;
private static final long SYSTEM_METRICS_REFRESH_INTERVAL = 1_000L;
@Override
@ -42,7 +45,17 @@ public class DefaultMetricsProvider implements MetricsProvider {
}
double systemCpuUsage = meterRegistry.get("system.cpu.usage").gauge().value();
if (Double.compare(systemCpuUsage, Double.NaN) == 0) {
systemCpuUsage = lastSystemCpuUsage;
} else {
lastSystemCpuUsage = systemCpuUsage;
}
double processCpuUsage = meterRegistry.get("process.cpu.usage").gauge().value();
if (Double.compare(processCpuUsage, Double.NaN) == 0) {
processCpuUsage = lastProcessCpuUsage;
} else {
lastProcessCpuUsage = processCpuUsage;
}
double jvmMemoryUsed = meterRegistry.get("jvm.memory.used").meter().measure().iterator().next().getValue();
double jvmMemoryMax = meterRegistry.get("jvm.memory.max").meter().measure().iterator().next().getValue();