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
ID | Description |
---|---|
| Exposes audit events information for the current application. Requires an |
| Displays a complete list of all the Spring beans in your application. |
| Exposes available caches. |
| Shows the conditions that were evaluated on configuration and auto-configuration classes and the reasons why they did or did not match. |
| Displays a collated list of all |
| Exposes properties from Spring’s |
| Shows any Flyway database migrations that have been applied. Requires one or more |
| Shows application health information. |
| Displays HTTP trace information (by default, the last 100 HTTP request-response exchanges). Requires an |
| Displays arbitrary application info. |
| Shows the Spring Integration graph. Requires a dependency on |
| Shows and modifies the configuration of loggers in the application. |
| Shows any Liquibase database migrations that have been applied. Requires one or more |
| Shows ‘metrics’ information for the current application. |
| Displays a collated list of all |
| Displays the scheduled tasks in your application. |
| Allows retrieval and deletion of user sessions from a Spring Session-backed session store. Requires a Servlet-based web application using Spring Session. |
| Lets the application be gracefully shutdown. Disabled by default. |
| Performs a thread dump. |
If your application is a web application (Spring MVC, Spring WebFlux, or Jersey), you can use the following additional endpoints:
ID | Description |
---|---|
| Returns an |
| Exposes JMX beans over HTTP (when Jolokia is on the classpath, not available for WebFlux). Requires a dependency on |
| Returns the contents of the logfile (if |
| Exposes metrics in a format that can be scraped by a Prometheus server. Requires a dependency on |
By default, all endpoints except for shutdown
are enabled.
management.endpoints.enabled-by-default=false
management.endpoint.info.enabled=true
由于端点可能包含敏感信息,因此应该仔细考虑何时公开它们。下表显示了内置终结点的默认公开:
ID | JMX | Web |
---|---|---|
| Yes | No |
| Yes | No |
| Yes | No |
| Yes | No |
| Yes | No |
| Yes | No |
| Yes | No |
| Yes | Yes |
| N/A | No |
| Yes | No |
| Yes | Yes |
| Yes | No |
| N/A | No |
| N/A | No |
| Yes | No |
| Yes | No |
| Yes | No |
| Yes | No |
| N/A | No |
| Yes | No |
| Yes | No |
| Yes | No |
| 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