Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
"component : spring-kafka-example":
"project: spring-kafka-example":
- changed-files:
- any-glob-to-any-file: 'spring-kafka-example/**/*'

"project: spring-prometheus-grafana-example":
- changed-files:
- any-glob-to-any-file: 'spring-prometheus-grafana-example/**/*'

"type: dependency-upgrade":
- changed-files:
- any-glob-to-any-file: spring-kafka-example/pom.xml
- any-glob-to-any-file:
- spring-kafka-example/pom.xml
- spring-prometheus-grafana-example/pom.xml

"ci: github-actions":
- changed-files:
Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/spring-prometheus-grafana-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ jobs:
compose-file: './spring-prometheus-grafana-example/compose.yaml'
services: |
app
prometheus
grafana
up-flags: '--build'
down-flags: '--volumes'

Expand All @@ -58,13 +60,17 @@ jobs:

- name: Check container health
run: |
echo "Verificando saúde dos containers..."
echo "Checking the health of the containers..."

APP_STATUS=$(docker inspect -f '{{.State.Running}}' app || echo "false")
PROMETHEUS_STATUS=$(docker inspect -f '{{.State.Running}}' prometheus || echo "false")
GRAFANA_STATUS=$(docker inspect -f '{{.State.Running}}' grafana || echo "false")

echo "Status do app: $APP_STATUS"
echo "App status: $APP_STATUS"
echo "Prometheus status: $PROMETHEUS_STATUS"
echo "Grafana status: $GRAFANA_STATUS"

if [ "$APP_STATUS" != "true" ]; then
if [ "$APP_STATUS" != "true" ] || [ "$PROMETHEUS_STATUS" != "true" ] || [ "$GRAFANA_STATUS" != "true" ]; then
echo "::error ::An error occurred while executing the containers."
exit 1
fi
Expand Down
48 changes: 48 additions & 0 deletions spring-prometheus-grafana-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# spring-prometheus-grafana-example

---

## Overview

This is a basic Java Spring project demonstrating how to integrate Prometheus and Grafana
to collect and visualize application metrics from a Spring Boot application.
Metrics are exposed via Spring Actuator and scraped by Prometheus, which are then displayed
in customizable dashboards using Grafana.

---

## Tech stack

- Spring Boot
- Spring Actuator
- Java 21
- Prometheus (Docker)
- Grafana (Docker)

---

## Ports

| Service | Local URL | Username/Password |
|------------|------------------------------------------------|-------------------|
| Prometheus | [http://localhost:9090](http://localhost:9090) | n/a |
| Grafana | [http://localhost:3000](http://localhost:3000) | admin/admin |

---

## Related Resources

| Description | Link |
|--------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Basic config spring + grafana + prometheus | [monitoring-spring-boot-applications-with-prometheus-and-grafana](https://hidev.cc/tutoriais-praticos/2025/03/monitorando-aplicacoes-spring-boot-com-prometheus-e-grafana/) |
| Grafana Dashboards Spring boot | [grafana.com/grafana/dashboards](https://grafana.com/grafana/dashboards/?search=spring+boot) |

---

## Dashboards Configured

| Name | File Path | Source |
|-------------------------|------------------------------------------------|----------------------------------------------------------------------------------------|
| Spring Boot JVM Metrics | `docker/dashboards/jvm-metrics-dashboard.json` | [Grafana Dashboard #4701](https://grafana.com/grafana/dashboards/4701-jvm-micrometer/) |

---
32 changes: 31 additions & 1 deletion spring-prometheus-grafana-example/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,35 @@ services:
container_name: app
build:
context: .
environment:
SERVER_PORT: 80
SPRING_PROFILES_ACTIVE: prd
ports:
- "80:80"
- "80:80"

prometheus:
container_name: prometheus
image: prom/prometheus:v3.5.0
ports:
- "9090:9090"
volumes:
- ./docker/prometheus.yml:/etc/prometheus/prometheus.yml
command:
- '--config.file=/etc/prometheus/prometheus.yml'
depends_on:
- app

grafana:
container_name: grafana
image: grafana/grafana:12.1.0
ports:
- "3000:3000"
depends_on:
- prometheus
environment:
- GF_SECURITY_ADMIN_USER=admin #⚠️ DO NOT USE IN PRODUCTION
- GF_SECURITY_ADMIN_PASSWORD=admin #⚠️ DO NOT USE IN PRODUCTION
volumes:
- ./docker/provisioning/datasources:/etc/grafana/provisioning/datasources
- ./docker/provisioning/dashboards:/etc/grafana/provisioning/dashboards
- ./docker/dashboards:/var/lib/grafana/dashboards
Loading