aboutsummaryrefslogtreecommitdiff
path: root/spark-common
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2020-03-24 14:58:11 +0000
committerLuck <git@lucko.me>2020-03-24 14:58:11 +0000
commitb86549b9ffcaeccdc15e965616a58a7d1ef0bcf6 (patch)
tree559e88e29d90872e19d91409f4fd2ebdb46b6852 /spark-common
parent1ff2aa9a9c9020af8e255c6f9d506e6765e6b59f (diff)
downloadspark-b86549b9ffcaeccdc15e965616a58a7d1ef0bcf6.tar.gz
spark-b86549b9ffcaeccdc15e965616a58a7d1ef0bcf6.tar.bz2
spark-b86549b9ffcaeccdc15e965616a58a7d1ef0bcf6.zip
Don't include negative cpu usage readings (null result) in averages
Diffstat (limited to 'spark-common')
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/monitor/cpu/CpuMonitor.java13
1 files changed, 9 insertions, 4 deletions
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);
+ }
}
}
}