Make CpuUsageGauge a CachedGauge.

This commit is contained in:
Jon Chambers
2020-08-10 11:52:03 -04:00
committed by Jon Chambers
parent 647a2aea64
commit 6646be8d94
2 changed files with 9 additions and 4 deletions

View File

@@ -1,21 +1,25 @@
package org.whispersystems.textsecuregcm.metrics;
import com.codahale.metrics.CachedGauge;
import com.codahale.metrics.Gauge;
import com.sun.management.OperatingSystemMXBean;
import java.lang.management.ManagementFactory;
import java.util.concurrent.TimeUnit;
public class CpuUsageGauge implements Gauge<Integer> {
public class CpuUsageGauge extends CachedGauge<Integer> {
private final OperatingSystemMXBean operatingSystemMXBean;
public CpuUsageGauge() {
public CpuUsageGauge(final long timeout, final TimeUnit timeoutUnit) {
super(timeout, timeoutUnit);
this.operatingSystemMXBean = (com.sun.management.OperatingSystemMXBean)
ManagementFactory.getOperatingSystemMXBean();
}
@Override
public Integer getValue() {
protected Integer loadValue() {
return (int) Math.ceil(operatingSystemMXBean.getSystemCpuLoad() * 100);
}
}