How to Monitor Your Spring Boot App with Prometheus and Grafana in Kubernetes


I've recently configured the Prometheus and Grafana stack on my Kubernetes cluster to monitor system performance, including memory, CPU, and network usage. In this post, I’ll walk you through how I integrated Prometheus into my Spring Boot application to expose application-level metrics. Let's dive in!
Outline
Prerequisites
Why Monitor Spring Boot with Prometheus
How It Works
Configure Spring Boot App
Configure Prometheus
Configure the Grafana Dashboard
Summary & Resources
Prerequisites
Before you start, make sure you have the following:
A running Kubernetes cluster
Prometheus installed
Grafana installed
ArgoCD (optional) — I used ArgoCD to update Prometheus config, but you can also configure it manually
Why Monitor Spring Boot with Prometheus?
You might wonder: If Prometheus is already monitoring my Kubernetes cluster, why do I need to monitor the Spring Boot app?
Cluster-level metrics only show infrastructure health. App-level metrics give you insights into how your application is behaving internally.
For example:
Request count and latency (
http_server_requests_seconds_count
)Active threads and thread pool usage
JVM memory and GC pauses
HikariCP connection pool metrics
Custom business metrics (e.g., number of logins, votes, etc.)
How It Works
Spring Boot exposes an endpoint
/actuator/prometheus
that provides metrics.Prometheus scrapes this endpoint at regular intervals.
Grafana visualizes these metrics using dashboards.
Configure Spring Boot App
1. Add Dependencies
Update your pom.xml
with the following:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
Actuator provides built-in endpoints to display performance information of your application, such as health, metrics, and more.
Micrometer then makes these built-in metrics in a Prometheus understandable format
2. Configure application.properties
This ensures our application is an exposed /actuator/prometheus
endpoint, so that later steps, Prometheus can scrape it.
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
⚠️ Exposing all actuator endpoints (
management.endpoints.web.exposure.include=*
) is okay for development, but in production, limit it to only what's necessary. See the Spring Actuator docs.
Start your app and visit:
/actuator
to see available endpoints/actuator/prometheus
to see Prometheus-readable metrics
That’s it! Your app is now ready to be scraped by Prometheus.
Configure Prometheus
We need to configure Prometheus to scrape metrics from our Spring Boot application. If you installed Prometheus on your own way add the following to your Prometheus config (e.g., prometheus.yml
):
- job_name: 'vote-spring-app'
metrics_path: '/actuator/prometheus'
scrape_interval: '10s'
static_configs:
- targets: ['vote.vote-app.svc.cluster.local:8080']
Replace
vote.vote-app.svc.cluster.local:8080
with your app's actual address (e.g.,localhost:8080
).
In my case, I’ve addedthe above config on the ArgoCD UI by:
Navigate to Application → kuber-prometheus-stack → Details → Parameters.
Edit the
Values
field with the config above.
After deployment, verify your Spring Boot app appears in Prometheus targets and is in the UP state:
Explore metrics like:
http_server_requests_seconds_count
http_server_requests_seconds_max
Configure Grafana Dashboard
While this step is optional, dashboards in Grafana make it easier to view all metrics in one place. And looking into every metric one by one by querying in Prometheus is a repetitive task. So let’s configure the Grafana dashboard.
You can create a Grafana dashboard on your own, but in this blog, I am going to use a pre-configured dashboard from Grafana Dashboards, which is the place you can find lots of great dashboards from the Grafana community. And I chose this Spring Boot 2.1 System Monitor dashboard.
Steps:
Visit your Grafana website
Use dashboard ID
11378
(Spring Boot 2.1 System Monitor)Go to Grafana → Import Dashboard
Enter the ID and select Prometheus as the data source
And voilà — your Spring Boot metrics dashboard is ready!
Summary
By integrating Spring Boot metrics into your Prometheus and Grafana stack:
You gain insights into your application’s performance and health
It complements your cluster-level observability
Dashboards give you real-time visibility
Resources
Subscribe to my newsletter
Read articles from Jack Japar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
