Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use metric-schema to report JVM Buffer Pool metrics
Browse files Browse the repository at this point in the history
Pritham Marupaka committed Sep 12, 2024

Unverified

No user is associated with the committer email.
1 parent acfe3f7 commit efbfbf0
Showing 2 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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.
23 changes: 22 additions & 1 deletion tritium-metrics-jvm/src/main/metrics/metrics.yml
Original file line number Diff line number Diff line change
@@ -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 pool.
direct.used:
type: gauge
docs: Total memory used by the pool.
direct.capacity:
type: gauge
docs: Total capacity of the pool.
mapped.count:
type: gauge
docs: Number of buffers in the pool.
mapped.used:
type: gauge
docs: Total memory used by the pool.
mapped.capacity:
type: gauge
docs: Total capacity of the pool.

0 comments on commit efbfbf0

Please sign in to comment.