Send Spring Boot Metrics into InfluxDB and Grafana

One of the notable Spring Boot 2 features is the introduction of Micrometer (SLF4J for application metrics).

Spring Boot ships with a whole series of built-in metrics collecting JVM metrics  (memory usage, garbage collection, threads, and classes), CPU usage, Tomcat metrics as well as others.

You can query the metrics using the actuator HTTP endpoint:

Please note that you need to authenticate if Spring Security is present.

Install InfluxDB and Grafana using Docker Compose

A simple way to run InfluxDB and Grafana locally is Docker Compose.

Start InfluxDB and Grafana with docker-compose up .

Grafana is now running on http://localhost:3000. The default user is admin/admin.

Send Spring Boot Metrics to InfluxDB

Micrometer can send metrics to a series of destination using just configuration. You’ll only need to add the specific dependency and a few configuration values.

Grafana Configuration

The missing pieces to get Grafana up and running are:

  1. Log in and change the admin password.
  2. Add the InfluxDB data source.
    (host: http://influxdb:8086, admin credentials as in docker-compose.yml)
  3. Create a Dashboard.

Fully Working Example

All steps above are combined into a working example published on github.com/gysel/spring-boot-metrics-influxdb. The example includes and automatic provisioning of Grafana. You don’t need to add a data source of a dashboard. Everything is configured in startup.

2 Replies to “Send Spring Boot Metrics into InfluxDB and Grafana”

    1. Thanks for your hint. I’ve spent some time on this and you are correct. The exact field is called “userName” in the source code, “user-name” is likely a variation that Spring Boot accepts.

      I’ve not encountered this issue in my setup because I missed INFLUXDB_HTTP_AUTH_ENABLED=true in my local setup and I linked Spring Boot and InfluxDB without any authentication. My example code on GitHub has now authentication enabled.

      This post is also updated to include correct authentication.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.