The Spring Boot Actuator module provides advanced production-ready features such as monitoring, metrics, health checks, etc. The Spring Boot Actuator enables you to monitor the application using HTTP endpoints and JMX. In this tutorial we will learn how to get started with it.

In order to kick-start the Spring Boot Actuator it is sufficient to include the spring-boot-starter-actuator to autoconfigure Actuator. You can then take advantage of Actuator’s features in order to monitor a Spring Boot application:

$ spring init -dweb,actuator actuator-demo

Here is the list of depdendencies which has been added:

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

	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-test</artifactId>
		<scope>test</scope>
	</dependency>
</dependencies>

Now if you run the entry point class, you can check the metrics available:

./mvnw spring-boot:run
INFO 10420 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 2 endpoint(s) beneath base path '/actuator'
INFO 10420 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
INFO 10420 --- [           main] c.example.actuatordemo.DemoApplication   : Started DemoApplication in 7.944 seconds (JVM running for 30.702)
INFO 10420 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
INFO 10420 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
INFO 10420 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 23 ms

As you can see from the Console logs, unlike in Spring Boot 1.x, Actuator comes with most endpoints disabled, thus, the only two available by default are /health and /info. We can check them, under the "actuator" context:

$ curl http://localhost:8080/actuator/health
{"status":"UP"}

We can also customize the data shown by the metrics. For example, if we want to customize the "/info", we can modify the "info.app" properties in application.properties:

info.app.name=Demo Spring Sample Application
info.app.description=This is an example of Spring Boot Actuator
info.app.version=1.0.0

This results in:

curl http://localhost:8080/actuator/info
{"build":{"name":"Demo Spring Sample Application","description":"This is an example of Spring Boot Actuator","version":"1.0.0"}}

How to enable additional Acutator endpoints

In order to enable all the available Actuator endpoints you have to set the following property into the application.properties file:

management.endpoints.web.exposure.include=*

As you can see from the Application Logs, now the following endpoints are available:

INFO 11550 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 15 endpoint(s) beneath base path '/actuator'

Let's check for example that it worked by requesting the "metrics" endpoint:

$ curl http://localhost:8080/actuator/metrics
{"names":["jvm.memory.max","jvm.threads.states","process.files.max","jvm.gc.memory.promoted","tomcat.cache.hit","tomcat.servlet.error","system.load.average.1m","tomcat.cache.access","jvm.memory.used","jvm.gc.max.data.size","http.server.requests","jvm.gc.pause","jvm.memory.committed","system.cpu.count","logback.events","tomcat.global.sent","jvm.buffer.memory.used","tomcat.sessions.created","jvm.threads.daemon","system.cpu.usage","jvm.gc.memory.allocated","tomcat.global.request.max","tomcat.global.request","tomcat.sessions.expired","jvm.threads.live","jvm.threads.peak","tomcat.global.received","process.uptime","tomcat.sessions.rejected","process.cpu.usage","tomcat.threads.config.max","jvm.classes.loaded","jvm.classes.unloaded","tomcat.global.error","tomcat.sessions.active.current","tomcat.sessions.alive.max","jvm.gc.live.data.size","tomcat.servlet.request.max","tomcat.threads.current","tomcat.servlet.request","process.files.open","jvm.buffer.count","jvm.buffer.total.capacity","tomcat.sessions.active.max","tomcat.threads.busy","process.start.time"]}

You can also explicitly enable/disable a specific endpoint (for example /beans), as follows:

management.endpoint.beans.enabled=true

To expose all enabled endpoints except one (for example /env), we use:

management.endpoints.web.exposure.include=*
management.endpoints.web.exposure.exclude=env

Configurable Endpoints

The following Actuator endpoints are autoconfigured by the Actuator starter with the default settings:

    • info: Displays arbitrary application info.
    • health: Shows application basic health info for unauthenticated users and full details for authenticated users.
    • beans: Shows a list of all Spring beans configured in the application.
    • autoconfig: Displays an autoconfiguration report showing all autoconfiguration candidates and the reason they were/were not applied.
    • mappings: Displays a collated list of all @RequestMapping paths.
    • configprops: Displays a collated list of all @ConfigurationProperties.
    • metrics: Shows metrics information for the current application.
    • env: Exposes properties from Spring’s ConfigurableEnvironment.
    • trace: Displays trace information (by default, the last 100 HTTP requests).
    • dump: Performs a thread dump.
    • loggers: Shows and modifies the configuration of loggers in the application.
    • auditevents: Exposes audit events information for the current application.
    • flyway: Shows any Flyway database migrations that have been applied.
    • liquibase: Shows any Liquibase database migrations that have been applied.
    • actuator: Provides a hypermedia-based “discovery page” for the other endpoints.
    • shutdown: Allows the application to be gracefully shut down (not enabled by default).