mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-20 07:58:03 +01:00
Make CpuUsageGauge a CachedGauge.
This commit is contained in:
committed by
Jon Chambers
parent
647a2aea64
commit
6646be8d94
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user