Operations 10 min read

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.

macrozheng
macrozheng
macrozheng
How to Visualize SpringBoot Metrics with Grafana and Prometheus Using Docker

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:

<code>docker pull grafana/grafana</code>

Run Grafana:

<code>docker run -p 3000:3000 --name grafana -d grafana/grafana</code>

Pull the Prometheus Docker image:

<code>docker pull prom/prometheus</code>

Create

prometheus.yml

in

/mydata/prometheus/

with basic configuration, e.g.:

<code>global:
  scrape_interval: 5s
</code>

Run Prometheus with the configuration file mounted:

<code>docker run -p 9090:9090 --name prometheus -v /mydata/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml -d prom/prometheus</code>

Access 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:

<code>cd node_exporter
./node_exporter >log.file 2>&1 &</code>

Verify metrics with

curl http://localhost:9100/metrics

.

Add a scrape job to

prometheus.yml

:

<code>scrape_configs:
  - job_name: node
    static_configs:
      - targets: ['192.168.5.78:9100']
</code>

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.

<code>&lt;dependencies&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
    &lt;/dependency&gt;
    &lt;!-- integrate micrometer for Prometheus --&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;io.micrometer&lt;/groupId&gt;
        &lt;artifactId&gt;micrometer-registry-prometheus&lt;/artifactId&gt;
    &lt;/dependency&gt;
&lt;/dependencies&gt;
</code>

Configure

application.yml

to expose the endpoint:

<code>management:
  endpoints:
    web:
      exposure:
        include: 'prometheus'
  metrics:
    tags:
      application: ${spring.application.name}
</code>

Run the SpringBoot container, then add a scrape job for its metrics (replace the IP with the container’s address):

<code>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']
</code>

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/

monitoringDockeralertingPrometheusSpringBootGrafanaNode Exporter
macrozheng
Written by

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.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.