From 255ec35c3b73d8a6949c9aad6b3740e84ecff838 Mon Sep 17 00:00:00 2001 From: Wenjun Ruan Date: Mon, 8 Jul 2024 21:43:59 +0800 Subject: [PATCH] Filter the NaN of system_cpu_usage/process_cpu_usage (#16289) --- .../meter/metrics/DefaultMetricsProvider.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/dolphinscheduler-meter/src/main/java/org/apache/dolphinscheduler/meter/metrics/DefaultMetricsProvider.java b/dolphinscheduler-meter/src/main/java/org/apache/dolphinscheduler/meter/metrics/DefaultMetricsProvider.java index e293e44a8d..d0187a467e 100644 --- a/dolphinscheduler-meter/src/main/java/org/apache/dolphinscheduler/meter/metrics/DefaultMetricsProvider.java +++ b/dolphinscheduler-meter/src/main/java/org/apache/dolphinscheduler/meter/metrics/DefaultMetricsProvider.java @@ -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();