Skip to main content
A complete walkthrough of instrumenting a Java service using the official Prometheus Java client library (client_java v1.x). See the overview for the general approach.

1. Add the Prometheus client dependency

Add these dependencies to your pom.xml (Maven):
Or with Gradle (build.gradle):

2. Register custom metrics and expose /metrics

Register default JVM metrics, define your own custom counters/gauges, and start an HTTP server that exposes them on /metrics:
This starts a separate HTTP server on port 9090 that responds to GET /metrics in Prometheus exposition format — including JVM metrics like jvm_memory_used_bytes, jvm_gc_pause_seconds, jvm_threads_live_threads, plus your custom emails_sent_total.
If you’re using Spring Boot, the typical approach is Spring Boot Actuator + Micrometer’s Prometheus registry. Add io.micrometer:micrometer-registry-prometheus and set management.endpoints.web.exposure.include=prometheus in application.properties. The /actuator/prometheus endpoint is then exposed on your main service port.

3. Declare the metrics endpoint in ops.json

Prometheus will now scrape http://<your-service>:9090/metrics every 15 seconds and make every metric — JVM and custom — available in Grafana.

4. Visualize JVM metrics with a community dashboard

Instead of building JVM dashboards from scratch, import a battle-tested community dashboard from grafana.com/grafana/dashboards. To import: in Grafana, go to Dashboards → New → Import, enter the dashboard ID, and select your LocalOps Prometheus data source. You’ll instantly see heap/non-heap memory, GC activity, thread counts, classloader stats, and more. Your custom application metrics (emails_sent_total, etc.) can be charted alongside in the same or a separate dashboard.