From 2c907c63af921a9968bafd87903c93fe732c692f Mon Sep 17 00:00:00 2001 From: Byunghwa Yun Date: Tue, 4 Oct 2016 15:24:42 +0900 Subject: [PATCH] NIFI-2858: - getSystemLoadAverage of OperatingSystemMXBean sometimes returns a negative value. - ProcessorLoadAverage sets -1.0. It added a defensive logic. - When load average is zero(load average: 0.00, 0.02, 0.04), systemLoad is zero. - This closes #1091 --- .../org/apache/nifi/cluster/manager/StatusMerger.java | 9 ++++++++- .../nifi/diagnostics/SystemDiagnosticsFactory.java | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/StatusMerger.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/StatusMerger.java index 7ad9e84433..38caba2372 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/StatusMerger.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/StatusMerger.java @@ -573,7 +573,14 @@ public class StatusMerger { target.setFreeNonHeapBytes(target.getFreeNonHeapBytes() + toMerge.getFreeNonHeapBytes()); target.setMaxHeapBytes(target.getMaxHeapBytes() + toMerge.getMaxHeapBytes()); target.setMaxNonHeapBytes(target.getMaxNonHeapBytes() + toMerge.getMaxNonHeapBytes()); - target.setProcessorLoadAverage(target.getProcessorLoadAverage() + toMerge.getProcessorLoadAverage()); + double systemLoad = target.getProcessorLoadAverage(); + double toMergeSystemLoad = toMerge.getProcessorLoadAverage(); + if (systemLoad >= 0 && toMergeSystemLoad >= 0) { + systemLoad += toMergeSystemLoad; + } else if (systemLoad < 0 && toMergeSystemLoad >= 0) { + systemLoad = toMergeSystemLoad; + } + target.setProcessorLoadAverage(systemLoad); target.setTotalHeapBytes(target.getTotalHeapBytes() + toMerge.getTotalHeapBytes()); target.setTotalNonHeapBytes(target.getTotalNonHeapBytes() + toMerge.getTotalNonHeapBytes()); target.setTotalThreads(target.getTotalThreads() + toMerge.getTotalThreads()); diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/diagnostics/SystemDiagnosticsFactory.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/diagnostics/SystemDiagnosticsFactory.java index da3f60396c..24685e9ebe 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/diagnostics/SystemDiagnosticsFactory.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/diagnostics/SystemDiagnosticsFactory.java @@ -67,8 +67,10 @@ public class SystemDiagnosticsFactory { systemDiagnostics.setAvailableProcessors(os.getAvailableProcessors()); final double systemLoad = os.getSystemLoadAverage(); - if (systemLoad > 0) { + if (systemLoad >= 0) { systemDiagnostics.setProcessorLoadAverage(systemLoad); + } else { + systemDiagnostics.setProcessorLoadAverage(-1.0); } // get the database disk usage