Spring boot actuator and its endpoints

Spring Boot Actuator is a sub-project of Spring Boot. It provides several production ready features to any spring boot application. Once it is added in any spring boot application, it exposes a number of REST endpoints to monitor your application. You can monitor your application health, version details, thread dumps, logger details, application bean details, etc. without writing any code to avail these features.

After configuring spring actuator in your project, you get around 15 built-in endpoints to manage and monitor your application by default. The list of these endpoints are provided below. In case you require more control, you can also add your own endpoints. Not only this spring actuator also provide flexibility to rename the existing REST endpoints to any custom name you want.

Creating a Spring Boot application with Actuator

Two ways to do that:

  1. Using Spring.io initializr – also select Actuator jar along with others.
  2. By creating a spring boot project and adding Actuator Dependency to it.

This annotation is basically used on the class with main method, to mark the class as the main class of the application.

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

Where Spring boot Parent version is:

<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>2.1.7.RELEASE</version>
  <relativePath/> <!-- lookup parent from repository -->
</parent>
       

And For Gradle,

dependencies {
  compile("org.springframework.boot:spring-boot-starter-actuator")
}
        

Monitoring your application through Actuator Endpoints

EndPointsAPI DescriptionDefault Value
actuatorIt provides a hypermedia-based “discovery page” for the other endpoints. It requires Spring HATEOAS to be on the classpath.True
auditeventsIt exposes audit events information for the current application.True
autoconfigIt is used to display an auto-configuration report showing all auto-configuration candidates and the reason why they ‘were’ or ‘were not’ applied.True
beansIt is used to display a complete list of all the Spring beans in your application.True
configpropsIt is used to display a collated list of all @ConfigurationProperties.True
dumpIt is used to perform a thread dump.True
envIt is used to expose properties from Spring’s ConfigurableEnvironment.True
flywayIt is used to show any Flyway database migrations that have been applied.True
healthIt is used to show application health information.False
infoIt is used to display arbitrary application info.False
loggersIt is used to show and modify the configuration of loggers in the application.True
liquibaseIt is used to show any Liquibase database migrations that have been applied.True
MetricsIt is used to show metrics information for the current application.True
mappingsIt is used to display a collated list of all @RequestMapping paths.True
shutdownIt is used to allow the application to be gracefully shutdown.True
traceIt is used to display trace information.True

Enabling and Disabling Actuator Endpoints

By Default it Exposes 2 endpoint(s) beneath base path ‘/actuator’

You can enable or disable an actuator endpoint by setting the property management.endpoint.id. enabled to true or false (where id is the identifier for the endpoint).

For example, to enable the shutdown endpoint, add the following to your application.properties file –

management.endpoint.shutdown.enabled=true

Exposing Actuator Endpoints

To enable the rest of the 15 endpoints , add the following to you applicaiton.properties

management.endpoints.web.exposure.include=*

Or if you want to expose only specific endpoint , then add the following to properties file

management.endpoints.web.exposure.include=health,info // this will enable only health and info rest end points.

Summary

In this spring boot actuator tutorial you have learnt about actuator and the amount of apis if offers to help you monitor and manage your applications health. These features you must add and explore in your spring boot application. Hope you liked it !