Backend Development 6 min read

Integrating Spring Boot with Micrometer, Prometheus, and Grafana for Monitoring and Docker Deployment

This article explains how to combine Spring Boot with Micrometer, Prometheus, and Grafana for metrics collection and visualization, and provides Maven dependencies, configuration snippets, and Docker commands to deploy a fully monitored backend service using Docker containers.

Selected Java Interview Questions
Selected Java Interview Questions
Selected Java Interview Questions
Integrating Spring Boot with Micrometer, Prometheus, and Grafana for Monitoring and Docker Deployment

This article series describes using Spring Boot, Dubbo, Docker, and integrating Spring Boot with Dubbo, MyBatis, and other open‑source frameworks, including the implementation of logging aspects, and continuous integration via GitLab‑CI to build Docker images.

Micrometer

Spring Boot 2.x includes a third‑party metrics Facade that is integrated with Micrometer . Micrometer implements the MeterRegistry specification for Prometheus, allowing Prometheus to scrape and process metrics from Spring Boot applications, which can then be displayed in real time via Grafana.

For more details on Micrometer features, refer to its official documentation at https://micrometer.io/docs .

Metrics Tag/Label

Whether a metric supports tag/label determines if it can be multi‑dimensional. Systems like StatsD do not support tags, so distinguishing metrics from different hosts often requires a prefix, which complicates queries and extensions. Supporting tags enables multi‑dimensional statistics and queries, such as adding a host identifier to JVM metrics for flexible filtering across hosts or data centers.

Instrumentation (埋点)

Maven Dependencies

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
    <version>${springboot.version}</version>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-undertow</artifactId>
    <version>${springboot.version}</version>
</dependency>

<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
    <version>1.1.2</version>
</dependency>

Application Configuration

management.metrics.export.prometheus.enabled=true
management.metrics.export.prometheus.step=1m
management.metrics.export.prometheus.descriptions=true
management.web.server.auto-time-requests=true
management.endpoints.web.exposure.include=health,info,env,prometheus,metrics,httptrace,threaddump,heapdump

Web Instrumentation (Undertow)

@SpringBootApplication
@EnableAspectJAutoProxy(proxyTargetClass = true)
@ComponentScan("com.test")
public class Starter {
    public static void main(String[] args) {
        new SpringApplicationBuilder(Starter.class)
            .web(WebApplicationType.SERVLET)
            .run(args);
    }
}

Prometheus

Prometheus is an open‑source monitoring system originally from SoundCloud. Its core components are:

Scraper: Periodically pulls metrics via HTTP according to the configured interval.

Time‑series database: Stores all collected metrics.

Simple user interface: Provides visualization, querying, and alerting capabilities.

Docker Installation

docker run -d \
    --name prometheus \
    --net dubbo \
    --hostname prom \
    -p 9090:9090 \
    -v /media/raid10/tmp/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
    prom/prometheus \
    --config.file=/etc/prometheus/prometheus.yml

To add a new target for Prometheus to scrape, edit the mounted prometheus.yml file with the appropriate endpoint configuration and restart the container.

Grafana

Grafana allows you to visualize data from various sources such as Elasticsearch, Prometheus, Graphite, and InfluxDB with rich charts. It can also generate alerts based on metric thresholds and notify via email, Slack, or other channels.

Docker Installation

docker run -d \
    --name grafana \
    --net dubbo \
    -p 3000:3000 \
    -e "GF_SERVER_ROOT_URL=http://grafana.server.name" \
    -e "GF_SECURITY_ADMIN_PASSWORD=secret" \
    grafana/grafana

After starting the container, Grafana is accessible on port 3000, where you can add Prometheus as a data source and create dashboards to monitor your Spring Boot application metrics.

backendMonitoringDockerPrometheusSpring BootGrafanaMicrometer
Selected Java Interview Questions
Written by

Selected Java Interview Questions

A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!

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.