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 detail? Let’s find out in this tutorial!

First, I will create a Spring Boot project with the Actuator and Web dependencies using Spring Initializr, then import it into IntelliJ IDE 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:

As you can see, although I do not do anything, my application exposes 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 all the APIs that Actuator exposes, displayed as follows::

Here, I will tell you some more information about the API “/actuator/health” which by default Actuator enables it from version 2.x, and the API “/actuator/info”. Other APIs, you can learn more according to your needs!

The first is the “/actuator/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 “/actuator/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 “/actuator/health” API, my application will always return the status as DOWN.

Introduction to Spring Boot Actuator

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

By default, if you do not declare any information about our application using environment variables with the property name starting with “info”, then when accessing this API, no information is returned.

Introduction to Spring Boot Actuator

But if I now enable to display environment variable information:

and configure some information for our example:

then when you run the application again and access the API “/actuator/info”, you will see the following results:

Introduction to Spring Boot Actuator

Add Comment