From ee1386db0229ebf84ead0001607ed03a4cd0fc53 Mon Sep 17 00:00:00 2001 From: noblenumbat360 <80497951+noblenumbat360@users.noreply.github.com> Date: Mon, 22 Mar 2021 13:08:49 +1100 Subject: [PATCH] NIFI-8317 heap and non_heap usage Prometheus metrics now return -1.0 when undefined. Signed-off-by: Matthew Burgess This closes #4920 --- .../java/org/apache/nifi/metrics/jvm/JmxJvmMetrics.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nifi-commons/nifi-metrics/src/main/java/org/apache/nifi/metrics/jvm/JmxJvmMetrics.java b/nifi-commons/nifi-metrics/src/main/java/org/apache/nifi/metrics/jvm/JmxJvmMetrics.java index 55969fc137..ed2c3269f1 100644 --- a/nifi-commons/nifi-metrics/src/main/java/org/apache/nifi/metrics/jvm/JmxJvmMetrics.java +++ b/nifi-commons/nifi-metrics/src/main/java/org/apache/nifi/metrics/jvm/JmxJvmMetrics.java @@ -139,12 +139,14 @@ public class JmxJvmMetrics implements JvmMetrics { @Override public double heapUsage() { - return (Double) getMetric(MEMORY_HEAP_USAGE); + double usage = (Double) getMetric(MEMORY_HEAP_USAGE); + return usage < 0 ? -1.0 : usage; } @Override public double nonHeapUsage() { - return (Double) getMetric(MEMORY_NON_HEAP_USAGE); + double usage = (Double) getMetric(MEMORY_NON_HEAP_USAGE); + return usage < 0 ? -1.0 : usage; } @Override