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

class-loading-monitoring.mddocs/

Class Loading Monitoring

Class loading statistics including total loaded and unloaded class counts, providing insight into application lifecycle and potential class loading issues.

Core Imports

import com.codahale.metrics.jvm.ClassLoadingGaugeSet;
import com.codahale.metrics.MetricRegistry;
import java.lang.management.ClassLoadingMXBean;

Capabilities

ClassLoadingGaugeSet

Monitors JVM class loading behavior through ClassLoadingMXBean integration.

/**
 * A set of gauges for JVM classloader usage.
 */
public class ClassLoadingGaugeSet implements MetricSet {
    /**
     * Creates a new set of class loading gauges using the default ClassLoadingMXBean.
     */
    public ClassLoadingGaugeSet();
    
    /**
     * Creates a new set of class loading gauges using a custom ClassLoadingMXBean.
     * @param mxBean the ClassLoadingMXBean to use for statistics
     */
    public ClassLoadingGaugeSet(ClassLoadingMXBean mxBean);
    
    /**
     * Returns all class loading metrics.
     * @return map of metric names to Metric instances
     */
    public Map<String, Metric> getMetrics();
}

Metrics Provided:

  • loaded - Total number of classes loaded since JVM start (cumulative count)
  • unloaded - Total number of classes unloaded since JVM start (cumulative count)

Usage Examples:

import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.jvm.ClassLoadingGaugeSet;
import java.lang.management.ManagementFactory;

// Basic usage with default ClassLoadingMXBean
MetricRegistry registry = new MetricRegistry();
registry.registerAll(new ClassLoadingGaugeSet());

// Access class loading metrics
Gauge<Long> totalLoaded = registry.getGauges().get("loaded");
Gauge<Long> totalUnloaded = registry.getGauges().get("unloaded");

System.out.println("Total classes loaded: " + totalLoaded.getValue());
System.out.println("Total classes unloaded: " + totalUnloaded.getValue());

// Calculate current loaded classes (approximation)
long currentlyLoaded = totalLoaded.getValue() - totalUnloaded.getValue();
System.out.println("Currently loaded classes: " + currentlyLoaded);

// Custom ClassLoadingMXBean usage
ClassLoadingMXBean customBean = ManagementFactory.getClassLoadingMXBean();
registry.registerAll(new ClassLoadingGaugeSet(customBean));

// Monitor class loading over time
long previousLoaded = totalLoaded.getValue();
long previousUnloaded = totalUnloaded.getValue();

// ... wait some time ...

long newLoaded = totalLoaded.getValue();
long newUnloaded = totalUnloaded.getValue();

long classesLoadedSinceLast = newLoaded - previousLoaded;
long classesUnloadedSinceLast = newUnloaded - previousUnloaded;

System.out.println("Classes loaded in period: " + classesLoadedSinceLast);
System.out.println("Classes unloaded in period: " + classesUnloadedSinceLast);

Monitoring Patterns:

  • Steady Growth in Loaded Classes: Normal during application startup and dynamic loading
  • High Unload Activity: May indicate frequent class reloading or memory pressure
  • No Unloading: Common in production applications with static class sets
  • Rapid Loading/Unloading Cycles: Possible indication of dynamic code generation or classloader leaks

Performance Implications:

  • Class loading can be expensive, especially with complex dependency graphs
  • Class unloading typically occurs during full GC when classes are no longer referenced
  • Monitoring ratios of loaded to unloaded classes helps identify potential memory leaks
  • Sudden spikes in class loading may correlate with application events or deployments

Common Use Cases:

  • Application Server Monitoring: Track deployments and redeployments
  • Dynamic Framework Monitoring: Monitor Spring, OSGi, or other dynamic loading frameworks
  • Memory Leak Detection: Identify classloader leaks through increasing loaded class counts
  • Performance Analysis: Correlate class loading with application startup times

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