Spring Boot Actuator

Actuator is the feature that Spring Boot provides for monitoring and managing applications in the production environment. It has features for health checking, auditing, metrics tracking, HTTP tracking, showing environment variables, and dumping threads. In this section, we will explore some of these features and turn on those that we will need for monitoring our application.

First of all, for the use Actuator, we need to add the following dependencies to pom.xml:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

At the time of writing, with JDK 8 we will also need to include the following dependency to avoid a compilation error:

<dependency>
<groupId>javax.interceptor</groupId>
<artifactId>javax.interceptor-api</artifactId>
<version>${javax.interceptor.version}</version>
</dependency>

And now, let's add the following settings to application.properties:

management.server.port=9000
management.endpoint.health.show-details=always
management.endpoints.web.exposure.include=health, info, metrics, env

As you can see, we open the Actuator at port 9000 and make it always show health details. The actuator points that we choose to expose are the following:

  • /actuator/health: Allows us to check the health status of the application. For example, if the application is still up, if the database, mail server, or the RabbitMQ server is up, as well as server disk space usage, and so on.
  • /actuator/info: Displays the general information about the application.
  • /actuator/metrics: Shows various sensitive metric information of the application.
  • /actuator/env: Displays the current environment properties, which is sensitive information.

There are many other built-in endpoints that Actuator supports. You can also create custom endpoints. We will not discuss them here. For our application, these four endpoints are good to go with.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.13.192