Skip to content

Commit 6454a93

Browse files
committed
pr review
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
1 parent 7803053 commit 6454a93

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

  • examples/example-otel-jvm-runtime-metrics/src/main/java/io/prometheus/metrics/examples/otelruntimemetrics

examples/example-otel-jvm-runtime-metrics/src/main/java/io/prometheus/metrics/examples/otelruntimemetrics/Main.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,15 @@ public static void main(String[] args) throws IOException, InterruptedException
5353
RuntimeMetrics runtimeMetrics =
5454
RuntimeMetrics.builder(openTelemetry).captureGcCause().emitExperimentalTelemetry().build();
5555

56-
// 5. Close RuntimeMetrics on shutdown to stop JMX metric collection.
57-
Runtime.getRuntime().addShutdownHook(new Thread(runtimeMetrics::close));
58-
59-
// 6. Expose both Prometheus and OTel metrics on a single endpoint.
56+
// 5. Expose both Prometheus and OTel metrics on a single endpoint.
6057
HTTPServer server = HTTPServer.builder().port(9400).registry(registry).buildAndStart();
6158

59+
// 6. Close RuntimeMetrics and server on shutdown to stop JMX metric collection.
60+
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
61+
runtimeMetrics.close();
62+
server.close();
63+
}));
64+
6265
System.out.println(
6366
"HTTPServer listening on port http://localhost:" + server.getPort() + "/metrics");
6467

0 commit comments

Comments
 (0)