Skip to content

15.1 Introducing Actuator

In a machine, an actuator is a component that’s responsible for controlling and moving a mechanism. In a Spring Boot application, the Spring Boot Actuator plays that same role, enabling us to see inside of a running application and, to some degree, control how the application behaves.

Using endpoints exposed by Actuator, we can ask things about the internal state of a running Spring Boot application, such as the following:

  • What configuration properties are available in the application environment?
  • What are the logging levels of various packages in the application?
  • How much memory is being consumed by the application?
  • How many times has a given HTTP endpoint been requested?
  • What is the health of the application and any external services it coordinates with?

To enable Actuator in a Spring Boot application, you simply need to add Actuator’s starter dependency to your build. In any Spring Boot application Maven pom.xml file, the following <dependency> entry does the trick:

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

Once the Actuator starter is part of the project build, the application will be equipped with several out-of-the-box Actuator endpoints, including those described in table 15.1.

Table 15.1:Actuator endpoints for peeking inside and manipulating the state of a running Spring Boot application

HTTP methodPathDescription是否默认启用
GET/auditeventsProduces a report of any audit events that have been fired
GET/beansDescribes all the beans in the Spring application context
GET/conditionsProduces a report of autoconfiguration conditions that either passed or failed, leading to the beans created in the application context
GET/configpropsDescribes all configuration properties along with the current values
GET, POST, DELETE/envProduces a report of all property sources and their properties available to the Spring application
GET/env/Describes the value of a single environment property
GET/healthReturns the aggregate health of the application and (possibly) the health of external dependent applications
GET/heapdumpDownloads a heap dump
GET/httptraceProduces a trace of the most recent 100 requests
GET/infoReturns any developer-defined information about the application
GET/loggersProduces a list of packages in the application along with their configured and effective logging levels
GETPOST/loggers/Returns the configured and effective logging level of a given logger; the effective logging level can be set with a POST request
GET/mappingsProduces a report of all HTTP mappings and their corresponding handler methods
GET/metricsReturns a list of all metrics categories
GET/metrics/Returns a multidimensional set of values for a given metric
GET/scheduledtasksLists all scheduled tasks否。
GET/threaddumpReturns a report of all application threads

In addition to HTTP endpoints, all of the Actuator endpoints in table 15.1, with the lone exception of /heapdump, are also exposed as JMX MBeans. We’ll look at the JMX side of Actuator in chapter 17.

Released under the MIT License.