Java 8 and Newer
The OpenTelemetry runtime-telemetry-java8 module provides JVM runtime metrics for Java 8 and newer using JMX.Installation
- Add the
otel4s-oteljavalibrary - Add the OpenTelemetry runtime metrics library
Registration
Register the runtime metrics producers manually:Metrics Collected
The Java 8 module collects these metrics:| Metric | Description | Unit |
|---|---|---|
process.runtime.jvm.memory.usage | Memory usage by pool | bytes |
process.runtime.jvm.memory.committed | Committed memory by pool | bytes |
process.runtime.jvm.memory.limit | Maximum memory by pool | bytes |
process.runtime.jvm.memory.usage_after_last_gc | Memory after last GC | bytes |
process.runtime.jvm.gc.duration | GC duration | ms |
process.runtime.jvm.threads.count | Thread count | threads |
process.runtime.jvm.classes.loaded | Loaded classes | classes |
process.runtime.jvm.classes.unloaded | Unloaded classes | classes |
process.runtime.jvm.cpu.utilization | CPU utilization | 1 |
Java 17 and Newer
The OpenTelemetry runtime-telemetry-java17 module provides enhanced JVM runtime metrics for Java 17 and newer using both JMX and JFR (Java Flight Recorder).Installation
- Add the
otel4s-oteljavalibrary - Add the OpenTelemetry runtime metrics library
Registration
Register the runtime metrics producers:Additional Metrics
The Java 17 module collects all Java 8 metrics plus:| Metric | Description | Unit |
|---|---|---|
process.runtime.jvm.memory.init | Initial memory | bytes |
process.runtime.jvm.system.cpu.utilization | System CPU utilization | 1 |
process.runtime.jvm.system.cpu.load_1m | 1-minute load average | 1 |
process.runtime.jvm.buffer.usage | Buffer pool usage | bytes |
process.runtime.jvm.buffer.limit | Buffer pool limit | bytes |
process.runtime.jvm.buffer.count | Number of buffers | buffers |
Configuration Options
Custom Metric Intervals
Control metric collection intervals through environment variables:Selective Metric Collection
Disable specific metric collectors if needed:Usage Examples
Complete Application
With Custom Application Metrics
Monitoring Dashboards
Common Metrics to Watch
-
Memory Pressure
process.runtime.jvm.memory.usage(heap)process.runtime.jvm.memory.usage_after_last_gc
-
GC Performance
process.runtime.jvm.gc.duration- GC frequency and pause times
-
Thread Health
process.runtime.jvm.threads.count- Thread growth over time
-
CPU Usage
process.runtime.jvm.cpu.utilizationprocess.runtime.jvm.system.cpu.utilization(Java 17+)
Best Practices
Use Java 17 metrics when possible
Use Java 17 metrics when possible
The Java 17 module provides more detailed metrics through JFR integration. If your application runs on Java 17 or newer, prefer the
runtime-telemetry-java17 module.Monitor memory after GC
Monitor memory after GC
process.runtime.jvm.memory.usage_after_last_gc is a better indicator of actual memory pressure than raw usage, as it shows memory that cannot be reclaimed.Set appropriate export intervals
Set appropriate export intervals
JVM metrics change frequently. Consider using a shorter export interval (e.g., 30 seconds) for better granularity in production.
Correlate with application metrics
Correlate with application metrics
Combine JVM metrics with your application-specific metrics to understand the relationship between resource usage and application behavior.
Troubleshooting
Metrics Not Appearing
Ensure the runtime metrics are properly registered:High Memory Usage
Metric collection itself has minimal overhead, but if you suspect issues:Next Steps
Metrics Guide
Learn how to create custom metrics
Configuration
Configure metric export settings