What is a Spring Actuator?
The Spring Actuator is used to monitor and manage the Spring web application. We can use it to monitor and manage the application with the help of HTTP endpoints or the JMX. Spring Actuator is a Spring Boot sub-module and provides built-in endpoints that we can enable and disable for our application.
Advantages of Monitoring/Managing the Application
- Reduces downtime.
- Boosts productivity.
- Improves Cybersecurity Management.
- Increases the conversion rate.
- Increases customer satisfaction.
To configure an Actuator in our application we need to add the following dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Once the above dependency is added we can check the health of the system like below.
We can also check info, metrics, and mappings by adding the following properties.
management.endpoint.gateway.enabled=true
management.endpoints.web.exposure.include=health,info,metrics,mappings
If we check for metrics we can get output like below. We can add a JSON formatting extension to our Chrome to see the formatted data. Or we can use Microsoft Edge to see the formatted data.
Actuator endpoints
- Actuator endpoints let you monitor and interact with your application.
- Spring Boot includes several built-in endpoints and enables you to add your own.
- For example, the health endpoint provides basic application health information. Each endpoint can be enabled or disabled
- If we want to enable or disable the info endpoint we can add the following property
management.endpoint.info.enabled=true
Since Endpoints may contain sensitive information, careful consideration should be given about when to expose them.
We have the following 2 properties where we can add which endpoints we can expose and which we can not
management.endpoints.web.exposure.include=health,info,metrics,mappings
management.endpoints.web.exposure.exclude=info
If we want to expose all and exclude some then we can add
management.endpoints.web.exposure.include=*
management.endpoints.web.exposure.exclude=info
Following is the list of actuator endpoints
Id | Description |
auditevents | Exposes audit events information for the current application. |
beans | Displays a complete list of all the Spring beans in your application. |
caches | Exposes available caches. |
conditions | Shows the conditions that were evaluated on configuration and auto-configuration classes and the reasons why they did or did not match. |
configprops | Displays a collated list of all @ConfigurationProperties. |
env | Exposes properties from Spring’s ConfigurableEnvironment. |
flyway | Shows any Flyway database migrations that have been applied. |
health | Shows application health information. |
httptrace | Displays HTTP trace information (by default, the last 100 HTTP request-response exchanges). |
info | Displays arbitrary application info. |
integrationgraph | Shows the Spring Integration graph. |
loggers | Shows and modifies the configuration of loggers in the application. |
liquibase | Shows any Liquibase database migrations that have been applied. |
metrics | Shows ‘metrics’ information for the current application. |
mappings | Displays a collated list of all @RequestMapping paths. |
scheduledtasks | Displays the scheduled tasks in your application. |
sessions | Allows retrieval and deletion of user sessions from a Spring Session-backed session store. Not available when using Spring Session’s support for reactive web applications. |
shutdown | Let the application be gracefully shut down. |
threaddump | Performs a thread dump. |
If the application is a web application (Spring MVC, Spring WebFlux, or Jersey), we have the following additional endpoints:
Id | Description |
heapdump | Returns an hprof heap dump file. |
jolokia | Exposes JMX beans over HTTP (when Jolokia is on the classpath, not available for WebFlux). |
logfile | Returns the contents of the log file (if logging.file or logging.path properties have been set). Supports the use of the HTTP Range header to retrieve part of the log file’s content. |
prometheus | Exposes metrics in a format that can be scraped by a Prometheus server. |