Springboot Actuator

1. 启用springboot actuator

<dependency>        <groupId>org.springframework.boot</groupId>                <artifactId>spring-boot-starter-actuator</artifactId>                </dependency>
                        ### 2. endpoint                        endpoint可以帮助你监控应用的信息, 例如,health endpoint提供基本的应用程序运行状况信息                        为了远程调用endpoint, 你必须通过http或者jmx去暴露该endpoint                        默认情况下, 你可以使用http去访问/actuator/endpoint-id来获取该endpoint所提供的信息                        例如: 你可以访问/actuator/health来获取应用的基本进行状况                        #### 内置的endpoint                        | ID                 | Description                                                  |            | :----------------- | :----------------------------------------------------------- |            | `auditevents`      | 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.                                      |                        如果你的应用是web application (Spring MVC, Spring WebFlux, or Jersey), 以下endpoint也是可用的:                        | ID           | Description                                                  |            | :----------- | :----------------------------------------------------------- |            | `heapdump`   | 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`. |                        #### 2.1 启用endpoints                        默认的, 除了shutdown以外的endpoint都是默认启用的, 使用如下配置关闭默认启用的endpoints, 然后为单独的endpoint配置是否启用                        ```yml            management:              endpoints:                  enable-by-default: false                    endpoint:                        info:                              enabled: true                              ```                                                            `enabled`选项控制着该endpoint是否被创建, 他的相关bean是否存在上下文中.                                                            #### 2.2 暴露endpoints                                                            一些endpoints将会暴露敏感的信息, 下表显示了默认情况下内置的endpoints的暴露情况                                                            | ID                 | JMX  | Web  |                              | :----------------- | :--- | :--- |                              | `auditevents`      | 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   |                                                            你可以使用如下配置去选择endpoint是否暴露http端口或者jmx:                                                            | Property                                    | Default        |                              | :------------------------------------------ | :------------- |                              | `management.endpoints.jmx.exposure.exclude` |                |                              | `management.endpoints.jmx.exposure.include` | `*`            |                              | `management.endpoints.web.exposure.exclude` |                |                              | `management.endpoints.web.exposure.include` | `info, health` |                                                            `include`表示需要暴露的endpoint, exclude表示不用暴露的, exclude选项优先于include选项, exclude和include都是list, *表示所有endpoint, 在yml中\*表示特殊用法, 使用"\*"代替                                                            for example:                                                            ```yml                              # 只暴露health, info的jxm                              management:                                endpoints:                                   jmx:                                        exposure:                                               include: info, health                                               # 暴露所有除了info, health的web端口                                                   web:                                                         exposure:                                                                 include: "*"                                                                         exclude: info, health                                                                         ```