Fix some metrics names/types.

This commit is contained in:
Jon Chambers
2020-10-11 12:27:47 -04:00
committed by Jon Chambers
parent c5147e0c68
commit 691ab3080d
6 changed files with 53 additions and 57 deletions

View File

@@ -1,19 +0,0 @@
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,25 @@
package org.whispersystems.textsecuregcm.metrics;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Tag;
import java.lang.management.BufferPoolMXBean;
import java.lang.management.ManagementFactory;
import java.util.List;
import static com.codahale.metrics.MetricRegistry.name;
public class BufferPoolGauges {
private BufferPoolGauges() {}
public static void registerMetrics() {
for (final BufferPoolMXBean bufferPoolMXBean : ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class)) {
final List<Tag> tags = List.of(Tag.of("name", bufferPoolMXBean.getName()));
Metrics.gauge(name(BufferPoolGauges.class, "count"), tags, bufferPoolMXBean, BufferPoolMXBean::getCount);
Metrics.gauge(name(BufferPoolGauges.class, "memory_used"), tags, bufferPoolMXBean, BufferPoolMXBean::getMemoryUsed);
Metrics.gauge(name(BufferPoolGauges.class, "total_capacity"), tags, bufferPoolMXBean, BufferPoolMXBean::getTotalCapacity);
}
}
}

View File

@@ -1,12 +0,0 @@
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,24 @@
package org.whispersystems.textsecuregcm.metrics;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Tag;
import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.util.List;
import static com.codahale.metrics.MetricRegistry.name;
public class GarbageCollectionGauges {
private GarbageCollectionGauges() {}
public static void registerMetrics() {
for (final GarbageCollectorMXBean garbageCollectorMXBean : ManagementFactory.getGarbageCollectorMXBeans()) {
final List<Tag> tags = List.of(Tag.of("name", garbageCollectorMXBean.getName()));
Metrics.gauge(name(GarbageCollectionGauges.class, "collection_count"), tags, garbageCollectorMXBean, GarbageCollectorMXBean::getCollectionCount);
Metrics.gauge(name(GarbageCollectionGauges.class, "collection_time"), tags, garbageCollectorMXBean, GarbageCollectorMXBean::getCollectionTime);
}
}
}

View File

@@ -1,12 +0,0 @@
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();
}
}