You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by tp...@apache.org on 2023/01/26 12:26:14 UTC

[nifi] branch main updated: NIFI-10974: Incorrect warning message on memory usage from MonitorMemory

This is an automated email from the ASF dual-hosted git repository.

tpalfy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new c3dd2569db NIFI-10974: Incorrect warning message on memory usage from MonitorMemory
c3dd2569db is described below

commit c3dd2569dbaddf11c1be114921e34cd9c96393a5
Author: Mark Bathori <ba...@gmail.com>
AuthorDate: Wed Dec 14 16:43:58 2022 +0100

    NIFI-10974: Incorrect warning message on memory usage from MonitorMemory
---
 .../src/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;
             }