Operations 14 min read

Export Spring Boot Actuator Metrics to InfluxDB & Prometheus – A Step‑by‑Step Guide

This article explains how to configure Spring Boot Actuator to export metrics to InfluxDB and Prometheus, covering Docker setup, Micrometer dependencies, application properties, sample controller code, test data generation, and visualisation with Grafana.

Programmer DD
Programmer DD
Programmer DD
Export Spring Boot Actuator Metrics to InfluxDB & Prometheus – A Step‑by‑Step Guide

Introduction

Spring Boot Actuator underwent major changes after the release of Spring Boot 2, adding support for WebFlux, InfluxDB, and simplifying configuration compared to the 1.5 version.

Running InfluxDB with Docker

Start an InfluxDB container:

$ docker run -d --name influx -p 8086:8086 influxdb

Connect to the container and create a database:

$ docker exec -it influx influx
Connected to http://localhost:8086 version 1.5.2
create database springboot
use springboot

Integrating Spring Boot with InfluxDB

Add the Micrometer InfluxDB registry and Spring Boot Actuator starter to pom.xml:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
  <groupId>io.micrometer</groupId>
  <artifactId>micrometer-registry-influx</artifactId>
</dependency>

Override the default InfluxDB connection properties because the container runs on a VM:

management:
  metrics:
    export:
      influx:
        db: springboot
        uri: http://192.168.99.100:8086

Sample REST Controller

@RestController
public class PersonController {
    @Autowired
    private PersonRepository repository;
    @GetMapping("/persons/{id}")
    public Person findById(@PathVariable("id") Integer id) {
        return repository.findById(id).orElse(null);
    }
    // other CRUD endpoints omitted for brevity
}

Database Configuration (MySQL)

Run MySQL in Docker and let Spring JPA create tables automatically:

$ docker run -d --name mysql -e MYSQL_DATABASE=grafana -e MYSQL_USER=grafana -e MYSQL_PASSWORD=grafana -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -p 33306:3306 mysql:5

Set JPA properties to update the schema:

spring:
  datasource:
    url: jdbc:mysql://192.168.99.100:33306/grafana?useSSL=false
    username: grafana
    password: grafana
    driverClassName: com.mysql.jdbc.Driver
  jpa:
    properties:
      hibernate:
        dialect: org.hibernate.dialect.MySQL5Dialect
        hbm2ddl:
          auto: update

Generating Test Metrics

A JUnit test creates random Person objects, posts them to the service, updates, reads, and deletes them, causing Actuator to emit HTTP request metrics.

int ix = new Random().nextInt(100000);
Person p = new Person();
// set fields …
Person saved = template.postForObject("http://localhost:2222/persons", p, Person.class);
// further GET, PUT, DELETE calls …

Viewing Metrics in InfluxDB

After the test runs, query InfluxDB for the http_server_requests measurement to see method, uri, status, and exception tags.

Grafana Visualization

Run Grafana in Docker:

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

Create a dashboard that queries InfluxDB for request counts, response times, and groups by method and URI.

Prometheus Integration

Enable the Prometheus endpoint in application.yml:

management:
  endpoint:
    prometheus:
      enabled: true

Run Prometheus in Docker, exposing port 9090 and pointing it to the Spring Boot actuator endpoint:

$ docker run -d --name prometheus -p 9090:9090 \
  -v /tmp/prometheus.yml:/etc/prometheus/prometheus.yml \
  --network springboot prometheus

Prometheus scrape_configs example:

scrape_configs:
- job_name: 'springboot'
  metrics_path: '/actuator/prometheus'
  static_configs:
  - targets: ['person-service:2222']

Add Prometheus as a data source in Grafana and build panels using queries such as rate(http_server_requests_seconds_sum[1m]) filtered by method and uri.

Conclusion

Spring Boot 2 provides richer Actuator metrics that can be exported to InfluxDB or Prometheus with minimal code changes, enabling powerful visualisation in Grafana and simplifying observability for modern backend services.

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.

DockermetricsPrometheusSpring BootInfluxDBGrafanaActuator
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

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.