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
This commit is contained in:
Byunghwa Yun 2016-10-04 15:24:42 +09:00 committed by Matt Gilman
parent 44cc7e0072
commit 2c907c63af
2 changed files with 11 additions and 2 deletions

View File

@ -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());

View File

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