Spring Boot
Monitoring spring boot applications using Apica Ascent
Spring Boot Actuator and Micrometer
Spring Boot Actuator is a subproject 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.
Next, in Spring Boot's application.properties
file, add the following line.
Restart the server and navigate to http://localhost:<port>/actuator/
to verify if the Actuator endpoints are enabled.
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@Timed
annotation, 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 Apica Ascent 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 Apica Ascent via Prometheus.
![](https://docs.apica.io/~gitbook/image?url=https%3A%2F%2F2948796384-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LmzGprckLqwd5v6bs6m%252Fuploads%252FWesnYT6fYCoOC1QzP5ea%252FSpring-boot.png%3Falt%3Dmedia%26token%3D36a8dc8c-428c-44e2-af9a-535739f905b0&width=768&dpr=4&quality=100&sign=4104d684&sv=1)
Last updated