Skip to content

Meehdi/spring-boot-grafana

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“Š Spring Boot + Grafana Monitoring Stack

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

GitHub Java Spring Boot ![Docker](https://img.shields.io/badge/docker compose-blue)

🌟 Features

  • βœ… 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

πŸš€ Quick Start

Prerequisites

  • Java 17+
  • Docker & Docker Compose
  • Gradle (included via wrapper)

Start the Stack

# 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

Access the Services

That's it! πŸŽ‰

πŸ“ Project Structure

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

πŸ§ͺ Testing the Endpoints

Manual Testing

# 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

Load Testing

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.

πŸ“Š Setting Up Grafana Dashboards

Import Pre-Built Dashboards

  1. Open Grafana at http://localhost:3000
  2. Login with admin / admin (change password when prompted)
  3. Click "+" β†’ "Import"
  4. Enter one of these dashboard IDs:
    • 4701 - JVM Micrometer
    • 11378 - Spring Boot Statistics
  5. Select Prometheus as the data source
  6. Click Import

View Logs

# 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

🚨 Troubleshooting

Prometheus Can't Connect to Spring Boot

Check if the app is running:

curl http://localhost:8080/actuator/health

Check Prometheus targets:

Check Docker networking:

docker exec prometheus ping spring-boot-app

Grafana Shows "No Data"

  1. Verify Prometheus is collecting metrics:

  2. Check Grafana data source:

    • Configuration β†’ Data Sources β†’ Prometheus
    • Click "Save & Test" - should show green checkmark
  3. Verify time range in Grafana (top right corner)

Can't Access Services

Check if containers are running:

docker compose ps

Restart everything:

docker compose down
docker compose up -d

πŸ”’ Production Considerations

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

Example Production application.yml

management:
  endpoints:
    web:
      exposure:
        include: prometheus,health  # Only essentials
  endpoint:
    health:
      show-details: never  # Don't expose details

πŸ“š Learn More

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

⭐ Show Your Support

If this project helped you, please give it a ⭐️!

πŸ‘€ Author

Made with ❀️ and β˜• by developers, for developers

About

Spring Boot Grafana Configuration

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published