A complete, production-ready monitoring solution for Spring Boot applications using Prometheus and Grafana. Get beautiful real-time dashboards in minutes!

- β Real-time metrics - Monitor your application performance live
- β Pre-configured dashboards - Professional visualizations out of the box
- β Custom metrics - Track business logic and technical metrics
- β Docker Compose - One command to start everything
- β Production-ready - Security and best practices included
- β Easy to extend - Add your own metrics and dashboards
- Java 17+
- Docker & Docker Compose
- Gradle (included via wrapper)
# Clone the repository
git clone https://github.com/yourusername/spring-boot-grafana.git
cd spring-boot-grafana
# Start all services
docker compose up -d
# Wait ~30 seconds for everything to initialize
- Spring Boot App: http://localhost:8080
- Prometheus: http://localhost:9090
- Grafana: http://localhost:3000 (admin/admin)
That's it! π
spring-boot-grafana/
βββ spring-boot-app/ # Spring Boot application
β βββ src/
β β βββ main/
β β βββ java/
β β β βββ com/meehdi/demo/
β β β βββ controller/
β β β β βββ MetricsController.java
β β β βββ config/
β β β βββ CustomMetricsConfig.java
β β βββ resources/
β β βββ application.yml
β βββ build.gradle
β βββ Dockerfile
βββ docker/ # Docker configurations
β βββ prometheus/
β β βββ prometheus.yml # Prometheus scraping config
β βββ grafana/
β βββ provisioning/
β βββ datasources/
β βββ datasource.yml
βββ docker compose.yml # Orchestration file
βββ test-endpoints.sh # Load testing script
βββ README.md
# Health check
curl http://localhost:8080/actuator/health
# Simple endpoint
curl http://localhost:8080/api/hello
# Random success/error endpoint
curl http://localhost:8080/api/random
# View current statistics
curl http://localhost:8080/api/metrics/stats
# View raw Prometheus metrics
curl http://localhost:8080/actuator/prometheus
Generate realistic traffic to populate your dashboards:
chmod +x test-endpoints.sh
./test-endpoints.sh
This script will continuously send requests to various endpoints, creating data for your Grafana dashboards.
- Open Grafana at http://localhost:3000
- Login with
admin
/admin
(change password when prompted) - Click "+" β "Import"
- Enter one of these dashboard IDs:
- 4701 - JVM Micrometer
- 11378 - Spring Boot Statistics
- Select Prometheus as the data source
- Click Import
# All services
docker compose logs -f
# Specific service
docker compose logs -f spring-boot-app
docker compose logs -f prometheus
docker compose logs -f grafana
Check if the app is running:
curl http://localhost:8080/actuator/health
Check Prometheus targets:
- Go to http://localhost:9090/targets
- Look for
spring-boot-app
- should show "UP"
Check Docker networking:
docker exec prometheus ping spring-boot-app
-
Verify Prometheus is collecting metrics:
- Go to http://localhost:9090
- Query:
api_requests_total
- Should show results
-
Check Grafana data source:
- Configuration β Data Sources β Prometheus
- Click "Save & Test" - should show green checkmark
-
Verify time range in Grafana (top right corner)
Check if containers are running:
docker compose ps
Restart everything:
docker compose down
docker compose up -d
Before deploying to production:
- Change Grafana admin password
- Limit exposed actuator endpoints
- Add authentication to Prometheus and Grafana
- Set up HTTPS/TLS
- Configure resource limits in docker compose
- Set up backup for Grafana dashboards
- Configure alerting rules
- Use persistent volumes for data
management:
endpoints:
web:
exposure:
include: prometheus,health # Only essentials
endpoint:
health:
show-details: never # Don't expose details
- Medium Article - Detailed tutorial
- Micrometer Documentation
- Prometheus Documentation
- Grafana Documentation
- Spring Boot Actuator
This project is licensed under the MIT License - see the LICENSE file for details.
If this project helped you, please give it a βοΈ!
- GitHub: @Meehdi
- Medium: @elmehdi.kzadri
- LinkedIn: El Mehdi KZADRI
Made with β€οΈ and β by developers, for developers