How to Visualize SpringBoot Metrics with Grafana and Prometheus Using Docker
This guide walks through installing Grafana and Prometheus with Docker, configuring node_exporter to collect system metrics, adding SpringBoot Actuator and Micrometer for application metrics, setting up Prometheus scrape jobs, and importing ready‑made Grafana dashboards to achieve real‑time monitoring and alerting.
Grafana Overview
Grafana is an open‑source data‑visualization and analysis tool that can display metrics from any source and includes alerting when thresholds are exceeded.
Prometheus Overview
Prometheus is a time‑series database (a MySQL‑like database with timestamps) that stores metrics; Grafana visualizes data but does not store it, so they are used together.
Installation
Using Docker is the simplest way to install Grafana and Prometheus.
Pull the Grafana Docker image: docker pull grafana/grafana Run Grafana:
docker run -p 3000:3000 --name grafana -d grafana/grafanaPull the Prometheus Docker image: docker pull prom/prometheus Create prometheus.yml in /mydata/prometheus/ with basic configuration, e.g.:
global:
scrape_interval: 5sRun Prometheus with the configuration file mounted:
docker run -p 9090:9090 --name prometheus -v /mydata/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml -d prom/prometheusAccess Grafana at http://<your-host>:3000 (default login admin:admin) and Prometheus at http://<your-host>:9090.
Monitoring System Metrics
Install node_exporter on the Linux host to expose system metrics, then let Prometheus scrape them.
Download the node_exporter package from Prometheus download page and extract it.
Run the exporter:
cd node_exporter
./node_exporter >log.file 2>&1 &Verify metrics with curl http://localhost:9100/metrics.
Add a scrape job to prometheus.yml:
scrape_configs:
- job_name: node
static_configs:
- targets: ['192.168.5.78:9100']Restart the Prometheus container and import a dashboard (e.g., “Node Exporter Full”, ID 1860) from the Grafana marketplace.
Monitoring a SpringBoot Application
Add spring-boot-starter-actuator and micrometer-registry-prometheus dependencies to the project’s pom.xml and expose the /actuator/prometheus endpoint.
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- integrate micrometer for Prometheus -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
</dependencies>Configure application.yml to expose the endpoint:
management:
endpoints:
web:
exposure:
include: 'prometheus'
metrics:
tags:
application: ${spring.application.name}Run the SpringBoot container, then add a scrape job for its metrics (replace the IP with the container’s address):
scrape_configs:
- job_name: 'mall-tiny-grafana'
scrape_interval: 5s
scrape_timeout: 10s
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['172.17.0.5:8088']After reloading Prometheus and importing a suitable dashboard (e.g., ID 14370), Grafana will display real‑time SpringBoot metrics.
Summary
To visualize metrics with Grafana, first expose metrics from the target system (using Actuator, Micrometer, node_exporter, etc.), let Prometheus scrape and store them, and finally configure Grafana to use Prometheus as a data source.
References
Grafana documentation: https://grafana.com/docs/grafana/latest/getting-started/getting-started-prometheus/
Node exporter guide: https://prometheus.io/docs/guides/node-exporter/
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
macrozheng
Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
