Spring Boot (vkspringboot) + Prometheus + Grafana — Complete Local Monitoring Guide (2025)
A full end-to-end local observability setup using Spring Boot, Prometheus, Grafana, and Docker Compose.
This guide works on:
✅ Windows
✅ macOS
✅ Linux
✅ IntelliJ / VS Code
✅ Step 0 — Create Spring Boot Project (Name: vkspringboot)
In IntelliJ / Spring Initializr:
-
Open IntelliJ → New Project
-
Select Spring Initializr
-
Fill project details:
| Field | Value |
|---|---|
| Group | com.example |
| Artifact | vkspringboot |
| Name | vkspringboot |
| Java Version | 17 or 21 |
| Packaging | Jar |
-
Select dependencies:
✅ Spring Web
✅ Spring Boot Actuator
✅ Micrometer Prometheus Registry
Click Create.
This generates your project:
✅ Step 1 — Add Dependencies to pom.xml
Ensure your pom.xml contains:
✅ Step 2 — Enable Prometheus Metrics Endpoint
Create or edit:
src/main/resources/application.properties
Metrics will appear at:
👉 http://localhost:8080/actuator/prometheus
✅ Step 3 — Create a Simple REST Controller
src/main/java/com/example/vkspringboot/HelloController.java
Test it:
✅ Step 4 — Create Dockerfile (Updated for vkspringboot)
Your Maven build produces:
So your Dockerfile must match it:
✅ Correct JAR name
✅ Java 17 (matches project)
✅ Step 5 — Docker Compose (App + Prometheus + Grafana)
Create docker-compose.yml in project root:
✅ Step 6 — Prometheus Config File
Create prometheus.yml in project root:
✅ Prometheus scrapes Spring Boot every 5 seconds
✅ Uses service name app from Docker Compose
✅ Step 7 — Build the Project + Run the Stack
1️⃣ Build the JAR
2️⃣ Start everything
✅ Step 8 — Access All Tools Locally
| Component | URL |
|---|---|
| ✅ Spring Boot App | http://localhost:8080/hello |
| ✅ Spring Metrics | http://localhost:8080/actuator/prometheus |
| ✅ Prometheus | http://localhost:9090 |
| ✅ Grafana | http://localhost:3000 (login: admin / admin) |
✅ Step 9 — Connect Grafana to Prometheus
In Grafana:
-
Go to Configuration → Data Sources
-
Add Prometheus
-
URL:
-
Click Save & Test
✅ Grafana is now connected.
✅ Step 10 — Import Spring Boot Dashboards
Grafana → Dashboard → Import → Enter ID:
✅ 11378 — Spring Boot Micrometer Dashboard
✅ 4701 — JVM + Spring Boot Metrics
You will now see:
✅ API Request Count
✅ Response Time
✅ JVM Memory
✅ CPU Usage
✅ GC Metrics
✅ Thread pools
✅ Uptime
✅ ✅ Final Summary
You now have a complete local observability platform for Spring Boot.
No comments:
Post a Comment