NIFI-9400: Ensure that we always use the CollectionUsage metrics in the mbeans instead of the Usage metrics.

Signed-off-by: Joe Gresock <jgresock@gmail.com>

This closes #5798.
This commit is contained in:
Mark Payne 2022-02-24 12:03:11 -05:00 committed by Joe Gresock
parent 9d3788ff05
commit 0d0912d34b
No known key found for this signature in database
GPG Key ID: 37F5B9B6E258C8B7
1 changed files with 7 additions and 6 deletions

View File

@ -98,7 +98,7 @@ public class MonitorMemory extends AbstractReportingTask {
// Only allow memory pool beans that support usage thresholds, otherwise we wouldn't report anything anyway
memPoolAllowableValues = ManagementFactory.getMemoryPoolMXBeans()
.stream()
.filter(MemoryPoolMXBean::isUsageThresholdSupported)
.filter(MemoryPoolMXBean::isCollectionUsageThresholdSupported)
.map(MemoryPoolMXBean::getName)
.map(AllowableValue::new)
.toArray(AllowableValue[]::new);
@ -188,10 +188,11 @@ public class MonitorMemory extends AbstractReportingTask {
} else {
final String percentage = thresholdValue.substring(0, thresholdValue.length() - 1);
final double pct = Double.parseDouble(percentage) / 100D;
calculatedThreshold = (long) (monitoredBean.getUsage().getMax() * pct);
calculatedThreshold = (long) (monitoredBean.getCollectionUsage().getMax() * pct);
}
if (monitoredBean.isUsageThresholdSupported()) {
monitoredBean.setUsageThreshold(calculatedThreshold);
if (monitoredBean.isCollectionUsageThresholdSupported()) {
monitoredBean.setCollectionUsageThreshold(calculatedThreshold);
}
}
}
@ -209,7 +210,7 @@ public class MonitorMemory extends AbstractReportingTask {
return;
}
final MemoryUsage usage = bean.getUsage();
final MemoryUsage usage = bean.getCollectionUsage();
if (usage == null) {
getLogger().warn("{} could not determine memory usage for pool with name {}", new Object[] {this,
context.getProperty(MEMORY_POOL_PROPERTY)});
@ -217,7 +218,7 @@ public class MonitorMemory extends AbstractReportingTask {
}
final double percentageUsed = (double) usage.getUsed() / (double) usage.getMax() * 100D;
if (bean.isUsageThresholdSupported() && bean.isUsageThresholdExceeded()) {
if (bean.isCollectionUsageThresholdSupported() && bean.isCollectionUsageThresholdExceeded()) {
if (System.currentTimeMillis() < reportingIntervalMillis + lastReportTime && lastReportTime > 0L) {
return;
}