Report GC metrics.

This commit is contained in:
Jon Chambers
2020-10-09 19:32:50 -04:00
committed by Jon Chambers
parent 8a595ed77a
commit 95428ab8b0
4 changed files with 47 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
package org.whispersystems.textsecuregcm.metrics;
import com.codahale.metrics.Gauge;
import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
abstract class AbstractGarbageCollectionGauge implements Gauge<Long> {
private final GarbageCollectorMXBean garbageCollectorMXBean;
public AbstractGarbageCollectionGauge() {
this.garbageCollectorMXBean = (GarbageCollectorMXBean)ManagementFactory.getGarbageCollectorMXBeans();
}
protected GarbageCollectorMXBean getGarbageCollectorMXBean() {
return garbageCollectorMXBean;
}
}

View File

@@ -0,0 +1,12 @@
package org.whispersystems.textsecuregcm.metrics;
/**
* A gauge that reports the total number of collections that have occurred in this JVM's lifetime.
*/
public class GarbageCollectionCountGauge extends AbstractGarbageCollectionGauge {
@Override
public Long getValue() {
return getGarbageCollectorMXBean().getCollectionCount();
}
}

View File

@@ -0,0 +1,12 @@
package org.whispersystems.textsecuregcm.metrics;
/**
* A gauge that reports the cumulative amount of time (in milliseconds) spent on garbage collection.
*/
public class GarbageCollectionTimeGauge extends AbstractGarbageCollectionGauge {
@Override
public Long getValue() {
return getGarbageCollectorMXBean().getCollectionTime();
}
}