To add the actuator to a Maven based project, add the following ‘Starter’ dependency:
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> </dependencies>执行器端点允许您监视应用程序并与之交互。springboot包括许多内置的端点,您可以添加自己的端点。例如,运行状况端点提供基本的应用程序运行状况信息。每个端点都可以通过HTTP或JMX启用或禁用并公开(使远程可访问)。
默认情况下,运行状况端点映射到/actuator/health
IDDescriptionauditevents
Exposes audit events information for the current application. Requires an AuditEventRepository bean.
beans
Displays a complete list of all the Spring beans in your application.
caches
Exposes available caches.
conditions
Shows the conditions that were evaluated on configuration and auto-configuration classes and the reasons why they did or did not match.
configprops
Displays a collated list of all @ConfigurationProperties.
env
Exposes properties from Spring’s ConfigurableEnvironment.
flyway
Shows any Flyway database migrations that have been applied. Requires one or more Flyway beans.
health
Shows application health information.
httptrace
Displays HTTP trace information (by default, the last 100 HTTP request-response exchanges). Requires an HttpTraceRepository bean.
info
Displays arbitrary application info.
integrationgraph
Shows the Spring Integration graph. Requires a dependency on spring-integration-core.
loggers
Shows and modifies the configuration of loggers in the application.
liquibase
Shows any Liquibase database migrations that have been applied. Requires one or more Liquibase beans.
metrics
Shows ‘metrics’ information for the current application.
mappings
Displays a collated list of all @RequestMapping paths.
scheduledtasks
Displays the scheduled tasks in your application.
sessions
Allows retrieval and deletion of user sessions from a Spring Session-backed session store. Requires a Servlet-based web application using Spring Session.
shutdown
Lets the application be gracefully shutdown. Disabled by default.
threaddump
Performs a thread dump.
If your application is a web application (Spring MVC, Spring WebFlux, or Jersey), you can use the following additional endpoints:
IDDescriptionheapdump
Returns an hprof heap dump file.
jolokia
Exposes JMX beans over HTTP (when Jolokia is on the classpath, not available for WebFlux). Requires a dependency on jolokia-core.
logfile
Returns the contents of the logfile (if logging.file.name or logging.file.path properties have been set). Supports the use of the HTTP Range header to retrieve part of the log file’s content.
prometheus
Exposes metrics in a format that can be scraped by a Prometheus server. Requires a dependency on micrometer-registry-prometheus.
By default, all endpoints except for shutdown are enabled.
management.endpoints.enabled-by-default=false management.endpoint.info.enabled=true由于端点可能包含敏感信息,因此应该仔细考虑何时公开它们。下表显示了内置终结点的默认公开:
IDJMXWebauditevents
Yes
No
beans
Yes
No
caches
Yes
No
conditions
Yes
No
configprops
Yes
No
env
Yes
No
flyway
Yes
No
health
Yes
Yes
heapdump
N/A
No
httptrace
Yes
No
info
Yes
Yes
integrationgraph
Yes
No
jolokia
N/A
No
logfile
N/A
No
loggers
Yes
No
liquibase
Yes
No
metrics
Yes
No
mappings
Yes
No
prometheus
N/A
No
scheduledtasks
Yes
No
sessions
Yes
No
shutdown
Yes
No
threaddump
Yes
No
*可用于选择所有终结点。例如,要通过HTTP公开除env和beans端点之外的所有内容,请使用以下属性:
management.endpoints.web.exposure.include=* management.endpoints.web.exposure.exclude=env,beans If your application is exposed publicly, we strongly recommend that you also secure your endpoints.If you deploy applications behind a firewall, you may prefer that all your actuator endpoints can be accessed without requiring authentication. You can do so by changing the management.endpoints.web.exposure.include property, as follows:
application.properties
management.endpoints.web.exposure.include=*CORS support is disabled by default and is only enabled once the management.endpoints.web.cors.allowed-origins property has been set. The following configuration permits GET and POST calls from the example.com domain:
CORS支持在默认情况下被禁用,并且仅在管理.endpoints.web.允许cors-已设置原点属性。以下配置允许来自example.com网站域:
management.endpoints.web.cors.allowed-origins=https://example.com management.endpoints.web.cors.allowed-methods=GET,POST