From 98a439966d2a7f20402ee98f7f12130729c4d930 Mon Sep 17 00:00:00 2001 From: Pritham Marupaka Date: Thu, 12 Sep 2024 11:34:01 -0400 Subject: [PATCH 1/4] Use metric-schema to report JVM Buffer Pool metrics --- .../tritium/metrics/jvm/JvmMetrics.java | 21 ++++++++++++++--- .../src/main/metrics/metrics.yml | 23 ++++++++++++++++++- 2 files changed, 40 insertions(+), 4 deletions(-) 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..12f245e59 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 (poolName.equals("direct")) { + jvmBuffersMetrics.directCount(nonNegative(pool::getCount)); + jvmBuffersMetrics.directUsed(nonNegative(pool::getMemoryUsed)); + jvmBuffersMetrics.directCapacity(nonNegative(pool::getTotalCapacity)); + } else if (poolName.equals("mapped")) { + 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. From 894b78f97c51ab513666b7aaabe03338a88bc662 Mon Sep 17 00:00:00 2001 From: svc-changelog Date: Thu, 12 Sep 2024 16:00:30 +0000 Subject: [PATCH 2/4] Add generated changelog entries --- changelog/@unreleased/pr-2018.v2.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelog/@unreleased/pr-2018.v2.yml 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 From 760295b5d4bdf83e9f1655fdd8cf27464dc941e2 Mon Sep 17 00:00:00 2001 From: svc-changelog Date: Thu, 12 Sep 2024 16:00:38 +0000 Subject: [PATCH 3/4] Add generated changelog entries From 98b87ef88bacaea8b4ce7b6445841a0b7352495e Mon Sep 17 00:00:00 2001 From: Pritham Marupaka Date: Thu, 12 Sep 2024 13:02:21 -0400 Subject: [PATCH 4/4] review change --- .../java/com/palantir/tritium/metrics/jvm/JvmMetrics.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 12f245e59..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 @@ -219,11 +219,11 @@ private static void registerJvmBufferPools(TaggedMetricRegistry registry) { JvmBuffersMetrics jvmBuffersMetrics = JvmBuffersMetrics.of(registry); for (BufferPoolMXBean pool : ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class)) { String poolName = pool.getName(); - if (poolName.equals("direct")) { + if ("direct".equals(poolName)) { jvmBuffersMetrics.directCount(nonNegative(pool::getCount)); jvmBuffersMetrics.directUsed(nonNegative(pool::getMemoryUsed)); jvmBuffersMetrics.directCapacity(nonNegative(pool::getTotalCapacity)); - } else if (poolName.equals("mapped")) { + } else if ("mapped".equals(poolName)) { jvmBuffersMetrics.mappedCount(nonNegative(pool::getCount)); jvmBuffersMetrics.mappedUsed(nonNegative(pool::getMemoryUsed)); jvmBuffersMetrics.mappedCapacity(nonNegative(pool::getTotalCapacity));