NIFI-10974: Incorrect warning message on memory usage from MonitorMemory

This commit is contained in:
Mark Bathori 2022-12-14 16:43:58 +01:00 committed by Tamas Palfy
parent b3f2d95092
commit c3dd2569db
1 changed files with 4 additions and 2 deletions

View File

@ -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;
}