From b86549b9ffcaeccdc15e965616a58a7d1ef0bcf6 Mon Sep 17 00:00:00 2001 From: Luck Date: Tue, 24 Mar 2020 14:58:11 +0000 Subject: Don't include negative cpu usage readings (null result) in averages --- .../java/me/lucko/spark/common/monitor/cpu/CpuMonitor.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'spark-common') diff --git a/spark-common/src/main/java/me/lucko/spark/common/monitor/cpu/CpuMonitor.java b/spark-common/src/main/java/me/lucko/spark/common/monitor/cpu/CpuMonitor.java index 47e3fac..9c75dde 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/monitor/cpu/CpuMonitor.java +++ b/spark-common/src/main/java/me/lucko/spark/common/monitor/cpu/CpuMonitor.java @@ -159,11 +159,16 @@ public enum CpuMonitor { BigDecimal systemCpuLoad = new BigDecimal(systemLoad()); BigDecimal processCpuLoad = new BigDecimal(processLoad()); - for (RollingAverage average : this.systemAverages) { - average.add(systemCpuLoad); + if (systemCpuLoad.signum() != -1) { // if value is not negative + for (RollingAverage average : this.systemAverages) { + average.add(systemCpuLoad); + } } - for (RollingAverage average : this.processAverages) { - average.add(processCpuLoad); + + if (processCpuLoad.signum() != -1) { // if value is not negative + for (RollingAverage average : this.processAverages) { + average.add(processCpuLoad); + } } } } -- cgit