Actuator endpoints allow you to monitor and interact with your application. Spring Boot includes many built-in endpoints, and you can also add your own. For example, the health endpoint provides basic health information for the application.
The way endpoints are exposed depends on the type of technology you employ. Most applications choose HTTP monitoring, where the endpoint's ID is mapped to a URL. For example, the health endpoint will be mapped to /health by default.
The following endpoints are available:
ID Description Sensitiveautoconfig | Displays an auto-configuration report showing all auto-configuration candidates and why they were or were not applied | true |
beans | Displays a complete list of all Spring Beans in an application | true |
configprops | Displays a curated list of all @ConfigurationProperties | true |
dump | perform a thread dump | true |
env | Expose properties from Spring ConfigurableEnvironment | true |
health | Displays the application's health information (a simple 'status' when accessed with an unauthenticated connection, full information details when accessed with an authenticated connection) | false |
info | Display arbitrary application information | false |
metrics | Displays 'metrics' information for the current application | true |
mappings | Displays a curated list of all @RequestMapping paths | true |
shutdown | Allows apps to shut down gracefully (not enabled by default) | true |
trace | Show trace information (defaults to the latest HTTP requests) | true |
Note : Depending on how an endpoint is exposed, the sensitive parameter may be used as a security hint. For example, a username/password is required when accessing a sensitive endpoint using HTTP (which may be reduced to disallowing access to the endpoint if web security is not enabled).
1、Enabling EndPoints
By default, all endpoints are open except shutdown. The following example drops the shutdown endpoint:
management.endpoint.shutdown.enabled=trueTo disable the default endpoint, just set the value of management.endpoints.enabled-by-default to false, the following example
Enable the info endpoint and disable other endpoints:
management.endpoints.enabled-by-default=false management.endpoint.info.enabled=true2、Exposing Endpoints
The endpoints may contain some sensitive information, and it is prudent to expose these endpoints in a production environment.
The following example only exposes the health and info endpoints:
management.endpoints.jmx.exposure.include=health,info
The following example exposes all endpoints, but disables the env and beans endpoints:
management.endpoints.web.exposure.include=* management.endpoints.web.exposure.exclude=env,beans3. Endpoint Security
A typical security setup is as follows:
@Configuration public class ActuatorSecurity extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests() .anyRequest().hasRole("ENDPOINT_ADMIN") .and() .httpBasic(); } }If you want to release access to all endpoints, add the following configuration to the application.properties file:
management.endpoints.web.exposure.include=*If you have increased security access restrictions and want to not require authorized access, you need to configure the following:
@Configuration public class ActuatorSecurity extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests() .anyRequest().permitAll() } }4. Health information
The following health information is automatically loaded:
Name | Description |
DiskSpaceHealthIndicator | |
DataSourceHealthIndicator | |
ElasticsearchHealthIndicator | |
InfluxDbHealthIndicator | |
JmsHealthIndicator | |
MailHealthIndicator | |
MongoHealthIndicator | |
RabbitHealthIndicator | |
RedisHealthIndicator |
5. Customize HealthIndicators
@Component public class MyHealthIndicator implements HealthIndicator { @Override public Health health() { int errorCode = check(); // perform some specific health check if (errorCode != 0) { return Health.down().withDetail("Error Code", errorCode).build(); } return Health.up().build(); } }
6. Customize Info
@Component public class ExampleInfoContributor implements InfoContributor { @Override public void contribute(Info.Builder builder) { builder.withDetail("example", Collections.singletonMap("key", "value")); } }