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 

IdDescription
auditeventsExposes audit events information for the current application.
beansDisplays a complete list of all the Spring beans in your application.
cachesExposes available caches.
conditionsShows the conditions that were evaluated on configuration and auto-configuration classes and the reasons why they did or did not match.
configpropsDisplays a collated list of all @ConfigurationProperties.
envExposes properties from Spring’s ConfigurableEnvironment.
flywayShows any Flyway database migrations that have been applied.
healthShows application health information.
httptraceDisplays HTTP trace information (by default, the last 100 HTTP request-response exchanges).
infoDisplays arbitrary application info.
integrationgraphShows the Spring Integration graph.
loggersShows and modifies the configuration of loggers in the application.
liquibaseShows any Liquibase database migrations that have been applied.
metricsShows ‘metrics’ information for the current application.
mappingsDisplays a collated list of all @RequestMapping paths.
scheduledtasksDisplays the scheduled tasks in your application.
sessionsAllows 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.
shutdownLet the application be gracefully shut down.
threaddumpPerforms a thread dump.

If the application is a web application (Spring MVC, Spring WebFlux, or Jersey), we have the following additional endpoints:

IdDescription
heapdumpReturns an hprof heap dump file.
jolokiaExposes JMX beans over HTTP (when Jolokia is on the classpath, not available for WebFlux).
logfileReturns 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.
prometheusExposes metrics in a format that can be scraped by a Prometheus server.

-A blog by Shwetali Khambe

Related Posts