Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use metric-schema to report JVM Buffer Pool metrics #2018

Merged
merged 4 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-2018.v2.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)) {
mpritham marked this conversation as resolved.
Show resolved Hide resolved
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.
Expand Down
23 changes: 22 additions & 1 deletion tritium-metrics-jvm/src/main/metrics/metrics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
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.