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:
- Using Spring.io initializr – also select Actuator jar along with others.
- 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
| EndPoints | API Description | Default Value |
|---|---|---|
| actuator | It provides a hypermedia-based “discovery page” for the other endpoints. It requires Spring HATEOAS to be on the classpath. | True |
| auditevents | It exposes audit events information for the current application. | True |
| autoconfig | It is used to display an auto-configuration report showing all auto-configuration candidates and the reason why they ‘were’ or ‘were not’ applied. | True |
| beans | It is used to display a complete list of all the Spring beans in your application. | True |
| configprops | It is used to display a collated list of all @ConfigurationProperties. | True |
| dump | It is used to perform a thread dump. | True |
| env | It is used to expose properties from Spring’s ConfigurableEnvironment. | True |
| flyway | It is used to show any Flyway database migrations that have been applied. | True |
| health | It is used to show application health information. | False |
| info | It is used to display arbitrary application info. | False |
| loggers | It is used to show and modify the configuration of loggers in the application. | True |
| liquibase | It is used to show any Liquibase database migrations that have been applied. | True |
| Metrics | It is used to show metrics information for the current application. | True |
| mappings | It is used to display a collated list of all @RequestMapping paths. | True |
| shutdown | It is used to allow the application to be gracefully shutdown. | True |
| trace | It 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 !