CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-io-dropwizard-metrics--metrics-jvm

JVM Integration for Metrics - A set of classes which allow you to monitor critical aspects of your Java Virtual Machine using Metrics

Pending
Overview
Eval results
Files

memory-monitoring.mddocs/

Memory Monitoring

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.

Core Imports

import com.codahale.metrics.jvm.MemoryUsageGaugeSet;
import com.codahale.metrics.MetricRegistry;
import java.lang.management.MemoryMXBean;
import java.lang.management.MemoryPoolMXBean;

Capabilities

MemoryUsageGaugeSet

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 Memory: total.init, total.used, total.max, total.committed
  • Heap Memory: heap.init, heap.used, heap.max, heap.committed, heap.usage (ratio)
  • Non-Heap Memory: non-heap.init, non-heap.used, non-heap.max, non-heap.committed, non-heap.usage (ratio)
  • Memory Pool Metrics: For each memory pool (e.g., Eden Space, Old Generation):
    • pools.{pool-name}.init, pools.{pool-name}.used, pools.{pool-name}.max
    • pools.{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 space
  • pools.PS-Old-Gen.* - Old generation space
  • pools.PS-Survivor-Space.* - Young generation survivor space
  • pools.Metaspace.* - Class metadata space
  • pools.Code-Cache.* - Compiled code cache

Memory 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

docs

buffer-pool-monitoring.md

class-loading-monitoring.md

cpu-time-monitoring.md

file-descriptor-monitoring.md

gc-monitoring.md

index.md

jmx-attribute-access.md

jvm-attributes.md

memory-monitoring.md

thread-monitoring.md

tile.json