Operations 9 min read

Monitoring Spring Boot Applications with Spring Actuator, Micrometer, Prometheus, and Grafana

This article demonstrates how to set up comprehensive monitoring for a Spring Boot application by integrating Spring Actuator, Micrometer, Prometheus, and Grafana, covering component introductions, sample code creation, Docker-based Prometheus and Grafana deployment, and dashboard configuration for real‑time metrics visualization.

Code Ape Tech Column
Code Ape Tech Column
Code Ape Tech Column
Monitoring Spring Boot Applications with Spring Actuator, Micrometer, Prometheus, and Grafana

In this tutorial we learn how to monitor a Spring Boot application using Spring Actuator, Micrometer, Prometheus, and Grafana. Although it may seem involved, the setup is straightforward.

1. Introduction

Monitoring a production application is essential for early detection of issues. By exposing internal metrics through Spring Actuator and Micrometer, and visualizing them with Prometheus and Grafana, developers can gain real‑time insight into application health.

2. Creating a Sample Application

Generate a Spring Boot project via Spring Initializr with dependencies Spring Boot Actuator , Prometheus , and Spring Web . Add a simple controller:

@RestController
public class MetricsController {

    @GetMapping("/endPoint1")
    public String endPoint1() {
        return "Metrics for endPoint1";
    }

    @GetMapping("/endPoint2")
    public String endPoint2() {
        return "Metrics for endPoint2";
    }
}

Run the application:

$ mvn spring-boot:run

Verify the endpoints with curl and view the Actuator endpoints (e.g., http://localhost:8080/actuator ).

3. Enabling Prometheus Export

Add the following line to application.properties to expose the Prometheus endpoint:

management.endpoints.web.exposure.include=health,info,metrics,prometheus

After restarting, access http://localhost:8080/actuator/prometheus to see the exported metrics.

4. Adding Prometheus

Create a prometheus.yml configuration file:

global:
  scrape_interval: 15s

scrape_configs:
  - job_name: 'myspringmetricsplanet'
    metrics_path: '/actuator/prometheus'
    static_configs:
      - targets: ['HOST:8080']

Run Prometheus in a Docker container:

$ docker run \
    -p 9090:9090 \
    -v /path/to/prometheus.yml:/etc/prometheus/prometheus.yml \
    prom/prometheus

If the container cannot reach the Spring Boot app, start it with host networking:

$ docker run \
    --name prometheus \
    --network host \
    -v /path/to/prometheus.yml:/etc/prometheus/prometheus.yml \
    -d prom/prometheus

5. Adding Grafana

Run Grafana in Docker:

$ docker run --name grafana -d -p 3000:3000 grafana/grafana

Access http://localhost:3000/ (default credentials admin/admin ), add a Prometheus data source, and import the JVM dashboard (ID 4701) or create a custom panel. Example panel query: http_server_requests_seconds_max .

6. Conclusion

We have set up basic monitoring for a Spring Boot application by combining Spring Actuator, Micrometer, Prometheus, and Grafana. This foundation can be extended with additional metrics and custom dashboards to suit more complex monitoring needs.

MonitoringprometheusSpring BootGrafanaActuatorMicrometer
Code Ape Tech Column
Written by

Code Ape Tech Column

Former Ant Group P8 engineer, pure technologist, sharing full‑stack Java, job interview and career advice through a column. Site: java-family.cn

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.