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

jvm-attributes.mddocs/

JVM Attributes

JVM runtime information including name, vendor details, and uptime tracking, providing essential system identification and runtime metrics.

Core Imports

import com.codahale.metrics.jvm.JvmAttributeGaugeSet;
import com.codahale.metrics.MetricRegistry;
import java.lang.management.RuntimeMXBean;

Capabilities

JvmAttributeGaugeSet

Provides key JVM runtime attributes for system identification and uptime monitoring.

/**
 * A set of gauges for the JVM name, vendor, and uptime.
 */
public class JvmAttributeGaugeSet implements MetricSet {
    /**
     * Creates a new set of JVM attribute gauges using the default RuntimeMXBean.
     */
    public JvmAttributeGaugeSet();
    
    /**
     * Creates a new set of JVM attribute gauges with a custom RuntimeMXBean.
     * @param runtime JVM management interface with access to system properties
     */
    public JvmAttributeGaugeSet(RuntimeMXBean runtime);
    
    /**
     * Returns all JVM attribute metrics.
     * @return map of metric names to Metric instances
     */
    public Map<String, Metric> getMetrics();
}

Metrics Provided:

  • name - JVM name and process identifier (e.g., "12345@hostname")
  • vendor - Formatted vendor information including VM vendor, name, version, and specification version
  • uptime - JVM uptime in milliseconds since start

Usage Examples:

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

// Basic usage with default RuntimeMXBean
MetricRegistry registry = new MetricRegistry();
registry.registerAll(new JvmAttributeGaugeSet());

// Access JVM attributes
Gauge<String> jvmName = registry.getGauges().get("name");
Gauge<String> jvmVendor = registry.getGauges().get("vendor");
Gauge<Long> jvmUptime = registry.getGauges().get("uptime");

System.out.println("JVM Name: " + jvmName.getValue());
System.out.println("JVM Vendor: " + jvmVendor.getValue());
System.out.println("JVM Uptime: " + jvmUptime.getValue() + " ms");

// Convert uptime to more readable format
long uptimeMs = jvmUptime.getValue();
long uptimeSeconds = uptimeMs / 1000;
long uptimeMinutes = uptimeSeconds / 60;
long uptimeHours = uptimeMinutes / 60;
long uptimeDays = uptimeHours / 24;

System.out.printf("JVM Uptime: %d days, %d hours, %d minutes, %d seconds%n",
    uptimeDays, 
    uptimeHours % 24, 
    uptimeMinutes % 60, 
    uptimeSeconds % 60);

// Custom RuntimeMXBean usage
RuntimeMXBean customRuntimeBean = ManagementFactory.getRuntimeMXBean();
registry.registerAll(new JvmAttributeGaugeSet(customRuntimeBean));

// Extract process ID from JVM name
String jvmNameValue = jvmName.getValue();
String processId = jvmNameValue.split("@")[0];
String hostname = jvmNameValue.split("@")[1];
System.out.println("Process ID: " + processId);
System.out.println("Hostname: " + hostname);

Vendor Information Format:

The vendor metric combines multiple runtime properties in a formatted string:

{VM Vendor} {VM Name} {VM Version} ({Specification Version})

Example vendor strings:

  • "Eclipse Adoptium OpenJDK 64-Bit Server VM 11.0.16+8 (11)"
  • "Oracle Corporation Java HotSpot(TM) 64-Bit Server VM 1.8.0_301-b09 (1.8)"
  • "Azul Systems, Inc. OpenJDK 64-Bit Server VM 17.0.4+8-LTS (17)"

Monitoring Applications:

  • System Identification: Identify JVM version and vendor in multi-environment deployments
  • Uptime Tracking: Monitor application availability and restart frequency
  • Process Monitoring: Extract process IDs for system-level monitoring integration
  • Environment Validation: Ensure applications run on expected JVM versions
  • Performance Correlation: Correlate performance metrics with JVM uptime patterns

Integration Examples:

// Health check integration
public class JvmHealthCheck extends HealthCheck {
    private final Gauge<Long> uptimeGauge;
    
    public JvmHealthCheck(MetricRegistry registry) {
        this.uptimeGauge = registry.getGauges().get("uptime");
    }
    
    @Override
    protected Result check() {
        long uptime = uptimeGauge.getValue();
        if (uptime < 60000) { // Less than 1 minute
            return Result.unhealthy("JVM recently restarted");
        }
        return Result.healthy("JVM uptime: " + uptime + "ms");
    }
}

// Logging integration
Logger logger = LoggerFactory.getLogger(Application.class);
logger.info("Starting application on {}", jvmVendor.getValue());
logger.info("JVM process: {}", jvmName.getValue());

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