# 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

1. Prerequisites
    
2. Why Monitor Spring Boot with Prometheus
    
3. How It Works
    
4. Configure Spring Boot App
    
5. Configure Prometheus
    
6. Configure the Grafana Dashboard
    
7. 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

1. Spring Boot exposes an endpoint `/actuator/prometheus` that provides metrics.
    
2. Prometheus scrapes this endpoint at regular intervals.
    
3. Grafana visualizes these metrics using dashboards.
    

---

## Configure Spring Boot App

### 1\. Add Dependencies

Update your `pom.xml` with the following:

```xml
<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.

```ini
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](https://docs.spring.io/spring-boot/reference/actuator/endpoints.html).

Start your app and visit:

* `/actuator` to see available endpoints
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1750275264786/37ad42ee-8469-4e30-960d-7adcc2518c20.png align="left")
    
* `/actuator/prometheus` to see Prometheus-readable metrics
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1750275386446/b1757104-7847-4784-aefe-517e84a0acd6.png align="left")
    

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`):

```yaml
- 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:

1. Navigate to **Application → kuber-prometheus-stack → Details → Parameters**.
    
2. Edit the `Values` field with the config above.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1750276574861/a6388cda-e433-4e34-b7f9-8255be94c6d7.png align="left")

After deployment, verify your Spring Boot app appears in Prometheus targets and is in the **UP** state:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1750276703527/1ba34376-850e-468b-92be-81e1fa7a6654.png align="left")

Explore metrics like:

* `http_server_requests_seconds_count`
    
* `http_server_requests_seconds_max`
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1750277009249/c499f0e4-0ba9-4393-83f8-149ad3720553.png align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1750277031789/c5e58ea2-acfa-4aec-aea0-67fecb86a062.png align="left")

---

## 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**](https://grafana.com/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**](https://grafana.com/grafana/dashboards/11378-justai-system-monitor/) dashboard.

### Steps:

1. Visit your Grafana website
    
2. Use dashboard ID `11378` (Spring Boot 2.1 System Monitor)
    
3. Go to **Grafana → Import Dashboard**
    
4. Enter the ID and select Prometheus as the data source
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1750277922214/6fd42571-5845-4c1e-8658-25ec54721ad3.png align="left")

And voilà — your Spring Boot metrics dashboard is ready!

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1750278595254/f6b0ae49-6341-47e9-86fb-924153a818e2.png align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1750278646762/3790c704-df86-49d6-ac70-10de77a931c9.png align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1750278699687/934b4187-85a9-4b2b-ba9a-a7e8dd1d18fa.png align="left")

---

## 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

* [Spring Boot + Prometheus Guide (Baeldung)](https://www.baeldung.com/spring-boot-prometheus)
    
* [Simform Blog on Monitoring Spring Boot](https://medium.com/simform-engineering/revolutionize-monitoring-empowering-spring-boot-applications-with-prometheus-and-grafana-e99c5c7248cf)
    
* [Spring Actuator Endpoints](https://docs.spring.io/spring-boot/reference/actuator/endpoints.html)
    
* [Kubernetes DNS Docs](https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/)
