Introduction
The spring-boot-actuator module provides a module for monitoring and managing the production environment. You can use http, jmx, ssh, telnet, etc. to manage and monitor applications. Auditing,
Health, and data gathering are automatically added to the application.
Implemetation
A simple spring boot proj
First, write a basic spring boot project.
Maven-based projects add ‘starter’ dependencies
1 | <dependency> |
When startting, some log messages can be found.
1 | 2014-08-28 09:57:40.953 INFO 4064 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/trace],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke() |
explation of the log
Specific description:
ID | desc | Sensitive |
---|---|---|
autoconfig | 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 collated list of all @ConfigurationProperties | true |
dump | Execute a thread dump | true |
env | Exposure from the Spring ConfigurableEnvironment property | true |
health | Showing the health information of the application (a simple ‘status’ is displayed when an unauthenticated connection is accessed, and all information is displayed using an authenticated connection) | false |
info | Display any application information | false |
metrics | Displays the currently applied ‘metrics’ information | true |
mappings | Displays a collated list of all @RequestMapping paths | true |
shutdown | Allows the app to turn off gracefully (not enabled by default) | true |
trace | Display trace information (defaults to some recent HTTP requests) | true |
Health Check
For example: http://localhost:7231/health
You can get results
1 | {Status: "UP",} |
Add in the application configuration
Endpoints.health.sensitive = false
At the second visit http://localhost:7231/health
1 | {Status: "UP", diskSpace: {status: "UP", free: 32516145152, threshold: 10485760}, |
You can check for health information in some other cases. The following HealthIndicators are automatically configured by Spring Boot (at the appropriate time):
Name | Description |
---|---|
DiskSpaceHealthIndicator | Low disk space detection |
DataSourceHealthIndicator | Checks whether the connection can be obtained from the DataSource |
MongoHealthIndicator | checks whether a Mongo database is up (up) |
RabbitHealthIndicator | Checks whether a Rabbit server is up (up) |
RedisHealthIndicator | checks whether a Redis server is up (up) |
SolrHealthIndicator | checks whether a Solr server is up (up) |
Customization Of course, you can register to achieve the HealthIndicator interface Spring beans, Health response needs to include a status and optional for display details.
1 | Import org.springframework.boot.actuate.health.HealthIndicator; |
Trace
Visit http://localhost:7231/trace to see the results, default to some of the latest HTTP requests
1 | [ |
Look at InMemoryTraceRepository, the default is 100 events, if necessary, you can define your own InMemoryTraceRepository instance. If desired, you can create your own alternative TraceRepository implementation.
ref