diff --git a/changelog/@unreleased/pr-2018.v2.yml b/changelog/@unreleased/pr-2018.v2.yml new file mode 100644 index 000000000..7170573ea --- /dev/null +++ b/changelog/@unreleased/pr-2018.v2.yml @@ -0,0 +1,5 @@ +type: improvement +improvement: + description: Use metric-schema to report JVM Buffer Pool metrics + links: + - https://github.com/palantir/tritium/pull/2018 diff --git a/tritium-metrics-jvm/src/main/java/com/palantir/tritium/metrics/jvm/JvmMetrics.java b/tritium-metrics-jvm/src/main/java/com/palantir/tritium/metrics/jvm/JvmMetrics.java index 4248af108..f9384e4a2 100644 --- a/tritium-metrics-jvm/src/main/java/com/palantir/tritium/metrics/jvm/JvmMetrics.java +++ b/tritium-metrics-jvm/src/main/java/com/palantir/tritium/metrics/jvm/JvmMetrics.java @@ -18,7 +18,6 @@ import com.codahale.metrics.Gauge; import com.codahale.metrics.RatioGauge; -import com.codahale.metrics.jvm.BufferPoolMetricSet; import com.codahale.metrics.jvm.ThreadDeadlockDetector; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Suppliers; @@ -31,6 +30,7 @@ import com.palantir.tritium.metrics.jvm.InternalJvmMetrics.AttributeUptime_EnablePreview; import com.palantir.tritium.metrics.jvm.InternalJvmMetrics.DnsCacheTtlSeconds_Cache; import com.palantir.tritium.metrics.registry.TaggedMetricRegistry; +import java.lang.management.BufferPoolMXBean; import java.lang.management.ClassLoadingMXBean; import java.lang.management.ManagementFactory; import java.lang.management.MemoryMXBean; @@ -69,8 +69,7 @@ public static void register(TaggedMetricRegistry registry) { OperatingSystemMetrics.register(registry); SafepointMetrics.register(registry); registerAttributes(metrics); - MetricRegistries.registerAll( - registry, "jvm.buffers", new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer())); + registerJvmBufferPools(registry); registerClassLoading(metrics); registerJvmMemory(registry); registerThreads(metrics); @@ -216,6 +215,22 @@ protected RatioGauge.Ratio getRatio() { }); } + private static void registerJvmBufferPools(TaggedMetricRegistry registry) { + JvmBuffersMetrics jvmBuffersMetrics = JvmBuffersMetrics.of(registry); + for (BufferPoolMXBean pool : ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class)) { + String poolName = pool.getName(); + if ("direct".equals(poolName)) { + jvmBuffersMetrics.directCount(nonNegative(pool::getCount)); + jvmBuffersMetrics.directUsed(nonNegative(pool::getMemoryUsed)); + jvmBuffersMetrics.directCapacity(nonNegative(pool::getTotalCapacity)); + } else if ("mapped".equals(poolName)) { + jvmBuffersMetrics.mappedCount(nonNegative(pool::getCount)); + jvmBuffersMetrics.mappedUsed(nonNegative(pool::getMemoryUsed)); + jvmBuffersMetrics.mappedCapacity(nonNegative(pool::getTotalCapacity)); + } + } + } + /** * Computes the total heap + non-heap result of applying the specified function. * If either value is negative, returns null to avoid misleading metric data. diff --git a/tritium-metrics-jvm/src/main/metrics/metrics.yml b/tritium-metrics-jvm/src/main/metrics/metrics.yml index 663536b1d..e5881ee37 100644 --- a/tritium-metrics-jvm/src/main/metrics/metrics.yml +++ b/tritium-metrics-jvm/src/main/metrics/metrics.yml @@ -147,4 +147,25 @@ namespaces: docs: Amount of committed memory in bytes for the JVM non-heap (e.g. direct memory). non-heap.usage: type: gauge - docs: Ratio of `jvm.memory.non-heap.used` to `jvm.memory.non-heap.max`. \ No newline at end of file + docs: Ratio of `jvm.memory.non-heap.used` to `jvm.memory.non-heap.max`. + jvm.buffers: + docs: Java virtual machine buffer pool metrics. + metrics: + direct.count: + type: gauge + docs: Number of buffers in the direct buffer pool. + direct.used: + type: gauge + docs: Total memory used by the direct buffer pool. + direct.capacity: + type: gauge + docs: Total capacity of the direct buffer pool. + mapped.count: + type: gauge + docs: Number of buffers in the mapped buffer pool. + mapped.used: + type: gauge + docs: Total memory used by the mapped buffer pool. + mapped.capacity: + type: gauge + docs: Total capacity of the mapped buffer pool.