Permalink
Browse files

Handle condition where OperatingSystemMXBean.getSystemLoadAverage() r…

…eturns a negative value.
  • Loading branch information...
1 parent 2d53be1 commit 55cab8c086db69030c881de4ae815a92a5b924de @pferraro pferraro committed Jul 17, 2012
View
20 core/src/main/java/org/jboss/modcluster/load/metric/impl/AverageSystemLoadMetric.java
@@ -24,27 +24,35 @@
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
+import org.jboss.logging.Logger;
import org.jboss.modcluster.container.Engine;
/**
- * Uses {@link OperatingSystemMXBean#getSystemLoadAverage} to calculate average system load. Only supported on Java 1.6 or
- * later.
+ * Uses {@link OperatingSystemMXBean#getSystemLoadAverage} to calculate average system load.
*
* @author Paul Ferraro
*/
public class AverageSystemLoadMetric extends AbstractLoadMetric {
+ private static final Logger logger = Logger.getLogger(AverageSystemLoadMetric.class);
+
private final OperatingSystemMXBean bean;
-
+
public AverageSystemLoadMetric() {
this(ManagementFactory.getOperatingSystemMXBean());
}
-
+
public AverageSystemLoadMetric(OperatingSystemMXBean bean) {
this.bean = bean;
}
-
+
@Override
public double getLoad(Engine engine) throws Exception {
- return this.bean.getSystemLoadAverage() / this.bean.getAvailableProcessors();
+ double load = this.bean.getSystemLoadAverage();
+ if (load < 0) {
+ logger.warnf("%s is not supported on this system and will be disabled.", this.getClass().getSimpleName());
+ this.setWeight(0);
+ return 0;
+ }
+ return load / this.bean.getAvailableProcessors();
}
}

0 comments on commit 55cab8c

Please sign in to comment.