Provides OpenTelemetry instrumentation for OSHI.
This instrumentation collects system metrics such as memory usage, network I/O, and disk operations.
Replace OPENTELEMETRY_VERSION with the latest release.
For Maven, add to your pom.xml dependencies:
<dependencies>
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-oshi</artifactId>
<version>OPENTELEMETRY_VERSION</version>
</dependency>
</dependencies>For Gradle, add to your dependencies:
implementation("io.opentelemetry.instrumentation:opentelemetry-oshi:OPENTELEMETRY_VERSION")import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.instrumentation.oshi.SystemMetrics;
import java.util.List;
// Get an OpenTelemetry instance
OpenTelemetry openTelemetry = ...;
List<AutoCloseable> observables = SystemMetrics.registerObservers(openTelemetry);
// The observers will automatically collect and export system metrics
// Close the observables when shutting down your application
observables.forEach(observable -> {
try {
observable.close();
} catch (Exception e) {
// Handle exception
}
});