Operations 5 min read

Exposing Spring Boot Metrics with Actuator and Monitoring via Prometheus and Grafana

This tutorial demonstrates how to add Actuator dependencies to a Spring Boot 1.5.7 application, expose Prometheus‑compatible metrics, collect them with a Dockerized Prometheus instance, and visualize the data using Grafana, including all required configuration files and code snippets.

Java Architect Essentials
Java Architect Essentials
Java Architect Essentials
Exposing Spring Boot Metrics with Actuator and Monitoring via Prometheus and Grafana

This article explains how to expose monitoring metrics from a Spring Boot 1.5.7 application, collect them with Prometheus, and visualize them with Grafana.

1. Add Actuator dependencies

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
    <groupId>io.prometheus</groupId>
    <artifactId>simpleclient_spring_boot</artifactId>
    <version>0.0.26</version>
</dependency>

Import the Prometheus client library to enable metric collection.

In the main application class ( Application.java) add the following annotations:

@SpringBootApplication
@EnablePrometheusEndpoint
@EnableSpringBootMetricsCollector
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

Configure a default login in application.yml:

security:
  user:
    name: user
    password: pwd

After starting the application, access http://localhost:8080/application/prometheus to see metrics in Prometheus format.

2. Set up Prometheus

Pull the Prometheus Docker image: $ docker pull prom/prometheus Create prometheus.yml with the following scrape configuration:

global:
  scrape_interval: 10s
  scrape_timeout: 10s
  evaluation_interval: 10m
scrape_configs:
  - job_name: spring-boot
    scrape_interval: 5s
    scrape_timeout: 5s
    metrics_path: /application/prometheus
    scheme: http
    basic_auth:
      username: admin
      password: 123456
    static_configs:
      - targets:
        - 192.168.11.54:8099  # Spring Boot IP and port

Run Prometheus with the configuration file mounted:

docker run -d --name prometheus -p 9090:9090 \
    -v D:\test\actuator\prometheus\prometheus.yml:/etc/prometheus/prometheus.yml \
    prom/prometheus

Verify the scrape status at http://localhost:9090/targets.

3. Set up Grafana

Pull and run the Grafana Docker image:

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

Log in with admin / admin, add a Prometheus data source pointing to http://localhost:9090, and create dashboard panels to display the collected metrics.

The article concludes with screenshots of the Grafana dashboards and a reminder to share the tutorial with others.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

monitoringPrometheusGrafanaActuatorspring-boot
Java Architect Essentials
Written by

Java Architect Essentials

Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.

0 followers
Reader feedback

How this landed with the community

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.