JVM Integration for Metrics - A set of classes which allow you to monitor critical aspects of your Java Virtual Machine using Metrics
—
Comprehensive memory usage tracking for the Java Virtual Machine including heap, non-heap, and individual memory pool statistics with usage ratios and garbage collection metrics.
import com.codahale.metrics.jvm.MemoryUsageGaugeSet;
import com.codahale.metrics.MetricRegistry;
import java.lang.management.MemoryMXBean;
import java.lang.management.MemoryPoolMXBean;Provides detailed memory usage metrics for all areas of JVM memory including total, heap, non-heap, and individual memory pools.
/**
* A set of gauges for JVM memory usage, including stats on heap vs. non-heap memory, plus GC-specific memory pools.
*/
public class MemoryUsageGaugeSet implements MetricSet {
/**
* Creates a new set of gauges using the default MemoryMXBean and MemoryPoolMXBeans.
*/
public MemoryUsageGaugeSet();
/**
* Creates a new set of gauges with custom MXBeans.
* @param mxBean the MemoryMXBean to use for memory statistics
* @param memoryPools collection of MemoryPoolMXBeans for pool-specific metrics
*/
public MemoryUsageGaugeSet(MemoryMXBean mxBean, Collection<MemoryPoolMXBean> memoryPools);
/**
* Returns all memory-related metrics.
* @return map of metric names to Metric instances
*/
public Map<String, Metric> getMetrics();
}Metrics Provided:
total.init, total.used, total.max, total.committedheap.init, heap.used, heap.max, heap.committed, heap.usage (ratio)non-heap.init, non-heap.used, non-heap.max, non-heap.committed, non-heap.usage (ratio)pools.{pool-name}.init, pools.{pool-name}.used, pools.{pool-name}.maxpools.{pool-name}.committed, pools.{pool-name}.usage (ratio)pools.{pool-name}.used-after-gc (if collection usage is supported)Usage Examples:
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.jvm.MemoryUsageGaugeSet;
// Basic usage with default MXBeans
MetricRegistry registry = new MetricRegistry();
registry.registerAll(new MemoryUsageGaugeSet());
// Access specific metrics
Gauge<Double> heapUsage = registry.getGauges().get("heap.usage");
Gauge<Long> heapUsed = registry.getGauges().get("heap.used");
Gauge<Long> heapMax = registry.getGauges().get("heap.max");
System.out.println("Heap usage ratio: " + heapUsage.getValue());
System.out.println("Heap used: " + heapUsed.getValue() + " bytes");
System.out.println("Heap max: " + heapMax.getValue() + " bytes");
// Custom MXBeans usage
MemoryMXBean customMemoryBean = ManagementFactory.getMemoryMXBean();
Collection<MemoryPoolMXBean> customPools = ManagementFactory.getMemoryPoolMXBeans();
registry.registerAll(new MemoryUsageGaugeSet(customMemoryBean, customPools));Memory Pool Examples:
Common memory pool names include:
pools.PS-Eden-Space.* - Young generation Eden spacepools.PS-Old-Gen.* - Old generation spacepools.PS-Survivor-Space.* - Young generation survivor spacepools.Metaspace.* - Class metadata spacepools.Code-Cache.* - Compiled code cacheMemory Usage Ratios:
Usage ratios are calculated as used/max, or used/committed when max is -1 (unlimited). Values range from 0.0 to 1.0, where 1.0 indicates full utilization.
Install with Tessl CLI
npx tessl i tessl/maven-io-dropwizard-metrics--metrics-jvm