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

@ -87,6 +87,8 @@ import org.whispersystems.textsecuregcm.mappers.RateLimitExceededExceptionMapper
import org.whispersystems.textsecuregcm.metrics.CpuUsageGauge;
import org.whispersystems.textsecuregcm.metrics.FileDescriptorGauge;
import org.whispersystems.textsecuregcm.metrics.FreeMemoryGauge;
import org.whispersystems.textsecuregcm.metrics.GarbageCollectionCountGauge;
import org.whispersystems.textsecuregcm.metrics.GarbageCollectionTimeGauge;
import org.whispersystems.textsecuregcm.metrics.MetricsApplicationEventListener;
import org.whispersystems.textsecuregcm.metrics.NetworkReceivedGauge;
import org.whispersystems.textsecuregcm.metrics.NetworkSentGauge;
@ -447,6 +449,8 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
environment.metrics().register(name(NetworkSentGauge.class, "bytes_sent"), new NetworkSentGauge());
environment.metrics().register(name(NetworkReceivedGauge.class, "bytes_received"), new NetworkReceivedGauge());
environment.metrics().register(name(FileDescriptorGauge.class, "fd_count"), new FileDescriptorGauge());
environment.metrics().register(name(GarbageCollectionCountGauge.class, "gc_count"), new GarbageCollectionCountGauge());
environment.metrics().register(name(GarbageCollectionTimeGauge.class, "gc_time"), new GarbageCollectionTimeGauge());
}
private void registerExceptionMappers(Environment environment, WebSocketEnvironment<Account> webSocketEnvironment, WebSocketEnvironment<Account> provisioningEnvironment) {

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();
}
}