Introduction to Spring Boot Actuator

The Spring Boot Actuator is a Spring tool that allows us to monitor our application on a production environment without any code at all. It will expose the information about the application, its status, how the data relates to the application, etc. How is it in details? Let’s find out in this tutorial!

First, I will create a Spring Boot project with the Actuator and Web dependencies as follows:

Introduction to Spring Boot Actuator

Now, I will start the Spring Boot project and go to http://localhost:8080/actuator, and you will see the following result:

Introduction to Spring Boot Actuator

As you can see, although I do not do anything, my application expose itself to some APIs starting with “/actuator” which will allow us to get information about our application.

For the old version 1.x, the Actuator exposes more APIs but in version 2.x, they have been disabled a lot. But we can enable them by declaring a property called management.endpoints.web.exposure.include in the application.properies file of our application. We can declare which API we need to enable with this property. To enable all of them, you can configure its value as follows:

Run the application again and access http://localhost:8080/actuator, and you will see the following 15 APIs:

Introduction to Spring Boot Actuator

including:

http://localhost:8080/actuator/auditevents

http://localhost:8080/actuator/beans

http://localhost:8080/actuator/caches

http://localhost:8080/actuator/health

http://localhost:8080/actuator/conditions

http://localhost:8080/actuator/configprops

http://localhost:8080/actuator/env

http://localhost:8080/actuator/info

http://localhost:8080/actuator/loggers

http://localhost:8080/actuator/heapdump

http://localhost:8080/actuator/threaddump

http://localhost:8080/actuator/metrics

http://localhost:8080/actuator/scheduledtasks

http://localhost:8080/actuator/httptrace

http://localhost:8080/actuator/mappings

Here, I will talk about some information of the two APIs that by default Actuator enable them from version 2.x.

The first is the “/health” API.

This API is used to allow other applications to check if the status of our application is running normally or stopped. You can click on the “/health” API to see what information it provides to us.

Introduction to Spring Boot Actuator

By default it only displays status information with the value of UP if our application is still running normally; otherwise, if there is any problem, the status will be DOWN.

We can implement the HealthIndicator interface to specify when our application is DOWN and when it is UP. For example, I have the AppHealthIndicator class that implements the HealthIndicator interface:

When running again and accessing the “/health” API, my application will always return status as DOWN.

Introduction to Spring Boot Actuator

Next, we’ll talk about the “/info” API.

By default, if you do not declare anything about our application using the property info.app.name, info.app.description, info.app.version, then when accessing this API, no information is returned.

Introduction to Spring Boot Actuator

But if I now configure the above information for our example:

Run again the application and access to the “/info” API, and you will see the following:

Introduction to Spring Boot Actuator

Please find out more about other API of Actuator to use.

Đánh giá bài viết
Chia sẽ bài viết này ...Share on Facebook
Facebook
2Tweet about this on Twitter
Twitter
Share on LinkedIn
Linkedin

Add Comment

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