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

Metrics JVM

Metrics JVM provides comprehensive Java Virtual Machine monitoring capabilities through the Dropwizard Metrics library. It enables real-time monitoring of critical JVM aspects including memory usage, garbage collection, thread states, class loading, buffer pools, and system attributes through JMX integration with minimal performance overhead.

Package Information

  • Package Name: io.dropwizard.metrics:metrics-jvm
  • Package Type: Maven
  • Language: Java
  • Installation:
    <dependency>
      <groupId>io.dropwizard.metrics</groupId>
      <artifactId>metrics-jvm</artifactId>
      <version>4.2.33</version>
    </dependency>

Core Imports

import com.codahale.metrics.jvm.*;
import com.codahale.metrics.MetricRegistry;

Basic Usage

import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.jvm.*;

// Create a metric registry
MetricRegistry registry = new MetricRegistry();

// Register JVM metrics
registry.registerAll(new MemoryUsageGaugeSet());
registry.registerAll(new GarbageCollectorMetricSet());
registry.registerAll(new ThreadStatesGaugeSet());
registry.registerAll(new ClassLoadingGaugeSet());
registry.registerAll(new JvmAttributeGaugeSet());

// For buffer pools (Java 7+)
registry.registerAll(new BufferPoolMetricSet(
    ManagementFactory.getPlatformMBeanServer()));

// Get specific metrics
Gauge<Double> heapUsage = registry.getGauges().get("heap.usage");
System.out.println("Heap usage: " + heapUsage.getValue());

Architecture

Metrics JVM is organized around several key components:

  • MetricSet Implementations: Provide collections of related metrics that can be registered with a MetricRegistry
  • Gauge Implementations: Individual metric providers for specific measurements
  • Utility Classes: Helper classes for thread dump generation and deadlock detection
  • JMX Integration: Direct integration with Java Management Extensions for real-time monitoring
  • Caching Support: Optional caching for performance optimization in high-frequency monitoring scenarios

Capabilities

Memory Monitoring

Comprehensive memory usage tracking including heap, non-heap, and individual memory pool statistics with usage ratios and garbage collection metrics.

public class MemoryUsageGaugeSet implements MetricSet {
    public MemoryUsageGaugeSet();
    public MemoryUsageGaugeSet(MemoryMXBean mxBean, Collection<MemoryPoolMXBean> memoryPools);
    public Map<String, Metric> getMetrics();
}

Memory Monitoring

Thread State Monitoring

Real-time thread state tracking, deadlock detection, and thread dump generation with optional caching for performance optimization.

public class ThreadStatesGaugeSet implements MetricSet {
    public ThreadStatesGaugeSet();
    public ThreadStatesGaugeSet(ThreadMXBean threads, ThreadDeadlockDetector deadlockDetector);
    public Map<String, Metric> getMetrics();
}

public class CachedThreadStatesGaugeSet extends ThreadStatesGaugeSet {
    public CachedThreadStatesGaugeSet(long interval, TimeUnit unit);
    public CachedThreadStatesGaugeSet(ThreadMXBean threadMXBean, ThreadDeadlockDetector deadlockDetector, long interval, TimeUnit unit);
}

Thread Monitoring

Garbage Collection Monitoring

Garbage collection statistics including collection counts and elapsed times for all discoverable garbage collectors.

public class GarbageCollectorMetricSet implements MetricSet {
    public GarbageCollectorMetricSet();
    public GarbageCollectorMetricSet(Collection<GarbageCollectorMXBean> garbageCollectors);
    public Map<String, Metric> getMetrics();
}

Garbage Collection Monitoring

Buffer Pool Monitoring

Buffer pool usage statistics for direct and mapped buffers, available on Java 7 and above.

public class BufferPoolMetricSet implements MetricSet {
    public BufferPoolMetricSet(MBeanServer mBeanServer);
    public Map<String, Metric> getMetrics();
}

Buffer Pool Monitoring

Class Loading Monitoring

Class loading statistics including total loaded and unloaded class counts.

public class ClassLoadingGaugeSet implements MetricSet {
    public ClassLoadingGaugeSet();
    public ClassLoadingGaugeSet(ClassLoadingMXBean mxBean);
    public Map<String, Metric> getMetrics();
}

Class Loading Monitoring

JVM Attributes

JVM runtime information including name, vendor details, and uptime tracking.

public class JvmAttributeGaugeSet implements MetricSet {
    public JvmAttributeGaugeSet();
    public JvmAttributeGaugeSet(RuntimeMXBean runtime);
    public Map<String, Metric> getMetrics();
}

JVM Attributes

File Descriptor Monitoring

File descriptor usage ratio monitoring for Unix-based systems.

public class FileDescriptorRatioGauge extends RatioGauge {
    public FileDescriptorRatioGauge();
    public FileDescriptorRatioGauge(OperatingSystemMXBean os);
}

File Descriptor Monitoring

JMX Attribute Access

Generic JMX attribute monitoring for custom MBean attributes.

public class JmxAttributeGauge implements Gauge<Object> {
    public JmxAttributeGauge(ObjectName objectName, String attributeName);
    public JmxAttributeGauge(MBeanServerConnection mBeanServerConn, ObjectName objectName, String attributeName);
    public Object getValue();
}

JMX Attribute Access

CPU Time Monitoring

CPU time measurement capabilities for performance monitoring.

public class CpuTimeClock extends Clock {
    public long getTick();
}

CPU Time Monitoring

Types

// Core Metrics library types
import com.codahale.metrics.MetricSet;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.RatioGauge;
import com.codahale.metrics.Clock;
import com.codahale.metrics.Metric;

// JMX types
import javax.management.MBeanServer;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;

// Java Management types
import java.lang.management.*;
import java.util.concurrent.TimeUnit;

Install with Tessl CLI

npx tessl i tessl/maven-io-dropwizard-metrics--metrics-jvm
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/io.dropwizard.metrics/metrics-jvm@4.2.x
Badge
tessl/maven-io-dropwizard-metrics--metrics-jvm badge