官方文档: Spring Boot Reference Documentation
Spring Boot包括了很多额外的特性来帮助我们监控和管理我们的应用.我们可以选择Http终端或者JMX
方式:
- HTTP
- JMX
引入依赖
1 2 3 4 5 6 | <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> </dependencies> |
命名由来
Actuator是一个制造业术语,指的是移动或者控制某物的机械装置.Actuator可以产生巨大的运动通过很小的变化.
Endpoint
Endpoint可以监控并且和我们的应用进行交互
id | 描述 | 默认JMX | 默认HTTP | 默认开启 |
auditevents | Exposes audit events information for the current application. Requires an AuditEventRepository bean. | Yes | No | |
beans | Displays a complete list of all the Spring beans in your application. | Yes | No | Y |
caches | Exposes available caches. | Yes | No | Y |
conditions | Shows the conditions that were evaluated on configuration and auto-configuration classes and the reasons why they did or did not match. | Yes | No | Y |
configprops | Displays a collated list of all @ConfigurationProperties. | Yes | No | Y |
env | Exposes properties from Spring’s ConfigurableEnvironment. | Yes | No | Y |
flyway | Shows any Flyway database migrations that have been applied. Requires one or more Flyway beans. | Yes | No | |
health | Shows application health information. | Yes | Yes | Y |
httptrace | Displays HTTP trace information (by default, the last 100 HTTP request-response exchanges). Requires an HttpTraceRepository bean. | Yes | No | Y |
info | Displays arbitrary application info. | Yes | No | Y |
integrationgraph | Shows the Spring Integration graph. Requires a dependency on spring-integration-core. | Yes | No | |
loggers | Shows and modifies the configuration of loggers in the application. | Yes | No | Y |
liquibase | Shows any Liquibase database migrations that have been applied. Requires one or more Liquibase beans. | Yes | No | |
metrics | Shows “metrics” information for the current application. | Yes | No | Y |
mappings | Displays a collated list of all @RequestMapping paths. | Yes | No | Y |
quartz | Shows information about Quartz Scheduler jobs. | Yes | No | Y |
scheduledtasks | Displays the scheduled tasks in your application. | Yes | No | Y |
sessions | Allows retrieval and deletion of user sessions from a Spring Session-backed session store. Requires a servlet-based web application that uses Spring Session. | Yes | No | |
shutdown | Lets the application be gracefully shutdown. Disabled by default. | Yes | No | N |
startup | Yes | No | ||
threaddump | Performs a thread dump. | Yes | No | Y |
下面的是web应用的endpoint
id | 描述 | 默认JMX | 默认HTTP | 默认开启 |
heapdump | Returns a heap dump file. On a HotSpot JVM, an HPROF-format file is returned. On an OpenJ9 JVM, a PHD-format file is returned. | N/A | No | Y |
jolokia | Exposes JMX beans over HTTP when Jolokia is on the classpath (not available for WebFlux). Requires a dependency on jolokia-core. | N/A | No | |
logfile | Returns the contents of the logfile (if the logging.file.name or the logging.file.path property has been set). Supports the use of the HTTP Range header to retrieve part of the log file’s content. | N/A | No | |
prometheus | Exposes metrics in a format that can be scraped by a Prometheus server. Requires a dependency on micrometer-registry-prometheus. | N/A | No | Y |
使用Actuator
HTTP 访问
/actuator/<id>
端⼝与路径
management.server.address=
management.server.port=
management.endpoints.web.base-path=/actuator
management.endpoints.web.path-mapping.<id>=路径
开启 Endpoint
management.endpoint.<id>.enabled=true
management.endpoints.enabled-by-default=false
暴露 Endpoint
management.endpoints.jmx.exposure.exclude=
management.endpoints.jmx.exposure.include=*
management.endpoints.web.exposure.exclude=
management.endpoints.web.exposure.include=info, health