From c3dd2569dbaddf11c1be114921e34cd9c96393a5 Mon Sep 17 00:00:00 2001 From: Mark Bathori Date: Wed, 14 Dec 2022 16:43:58 +0100 Subject: [PATCH] NIFI-10974: Incorrect warning message on memory usage from MonitorMemory --- .../main/java/org/apache/nifi/controller/MonitorMemory.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-reporting-tasks/src/main/java/org/apache/nifi/controller/MonitorMemory.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-reporting-tasks/src/main/java/org/apache/nifi/controller/MonitorMemory.java index 7c3ef52928..08078482c6 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-reporting-tasks/src/main/java/org/apache/nifi/controller/MonitorMemory.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-reporting-tasks/src/main/java/org/apache/nifi/controller/MonitorMemory.java @@ -143,6 +143,7 @@ public class MonitorMemory extends AbstractReportingTask { private volatile MemoryPoolMXBean monitoredBean; private volatile String threshold = "65%"; + private volatile long calculatedThreshold; private volatile long lastReportTime; private volatile long reportingIntervalMillis; private volatile boolean lastValueWasExceeded; @@ -182,7 +183,6 @@ public class MonitorMemory extends AbstractReportingTask { if (desiredMemoryPoolName.equals(memoryPoolName)) { monitoredBean = memoryPoolBean; if (memoryPoolBean.isCollectionUsageThresholdSupported()) { - long calculatedThreshold; if (DATA_SIZE_PATTERN.matcher(thresholdValue).matches()) { calculatedThreshold = DataUnit.parseDataSize(thresholdValue, DataUnit.B).longValue(); } else { @@ -218,7 +218,9 @@ public class MonitorMemory extends AbstractReportingTask { } final double percentageUsed = (double) usage.getUsed() / (double) usage.getMax() * 100D; - if (bean.isCollectionUsageThresholdSupported() && bean.isCollectionUsageThresholdExceeded()) { + // In certain scenarios in the monitored memory bean the gcSensor can get stuck in 'on' state before the usage would reach the threshold + // and this will cause false exceeded state until the next garbage collection. To eliminate this we are adding a condition with the calculated usage threshold. + if (bean.isCollectionUsageThresholdSupported() && bean.isCollectionUsageThresholdExceeded() && usage.getUsed() > calculatedThreshold) { if (System.currentTimeMillis() < reportingIntervalMillis + lastReportTime && lastReportTime > 0L) { return; }