Spring Boot
Monitoring spring boot applications using Logiq

Spring Boot Actuator and Micrometer

Spring Boot Actuator is a sub-project of Spring Boot that adds several production-grade services to your application with little effort on your part. It exposes various operational information about the running application - health, metrics, audit entries, scheduled tasks, env settings, etc. You can query the data via several HTTP endpoints. In this guide, we discuss how to enable API and other metrics using Actuator and micrometer.
Micrometer provides a simple facade over the instrumentation clients for the most popular monitoring systems, allowing you to instrument your JVM-based application code without vendor lock-in. Think SLF4J, but for metrics.

Enabling Actuator and Micrometer dependencies

In Spring Boot's pom.xml file, add the Spring Boot Actuator and Micrometer dependencies to enable Prometheus monitoring, as shown below.
1
// Enable Actuator dependency
2
<dependency>
3
<groupId>org.springframework.boot</groupId>
4
<artifactId>spring-boot-starter-actuator</artifactId>
5
</dependency>
6
7
// Enable Micrometer Prometheus dependency
8
<dependency>
9
<groupId>io.micrometer</groupId>
10
<artifactId>micrometer-registry-prometheus</artifactId>
11
<scope>runtime</scope>
12
</dependency>
Copied!
Next, in Spring Boot's application.properties file, add the following line.
1
// Enable Actuator Endpoints in application.properties
2
management.endpoints.web.exposure.include=health,info,prometheus
Copied!
Restart the server and navigate to http://localhost:<port>/actuator/ to verifiy if the Actuator endpoints are enabled.
Actuator Endpoints
Navigate to http://localhost:<port>/actuator/prometheus and verify if your Prometheus metrics are being displayed.

Enable API Timings

Micrometer comes with a timed annotation. Annotate Spring Controller methods with the@Timedannotation, as shown below.
Restart the server, invoke your APIs a few times and navigate to http://localhost:<port>/actuator/prometheus. You will now see the API stats being displayed along with other metrics.
Once these metrics are available, you can use LOGIQ to visualize them and set up alerts for important events. The following image depicts an example of Spring Boot monitoring dashboard built by visualizing metrics ingested into LOGIQ via Prometheus.
Logiq Spring Boot Monitoring Dashboard