第一部分:配置pom.xml
注意:请在springboot的环境下使用,就不用配置版本信息 注意:以下内容属于springboot2.3.3.RELEASE(我学习时使用的版本)
< dependencies>
< dependency>
< groupId> org.springframework.boot</ groupId>
< artifactId> spring-boot-starter-actuator</ artifactId>
</ dependency>
</ dependencies>
第二部分:Endpoints
这里的ID以及描述来自于官方文档 ,在此我只是作简单翻译,并查询网上以及存在的其他翻译做以书写,如有不当,请及时指出。 对第一个端点的路径举个简单例子:【http://localhost:8080/actuator】下面表格中的路径都是忽略了localhost:8080的路径,望知悉。 2.x中的端点conditions在1.x中的名称是autoconfig。 以下路径只是最简单的访问方式,还有通过加参数进行更详细内容的访问亟待后续更新。
1、端点简单介绍
ID 路径 描述 actuator /actuator 所有通过HTTP暴露的endpoints端点的ID以及路径(访问方式) beans /actuator/beans 提供有关应用程序bean的信息 auditevents /actuator/auditevents 提供有关应用程序的审核事件的信息 caches /actuator/caches 提供对应用程序缓存的访问 conditions /actuator/conditions 提供有关计算配置和自动配置类的条件的信息 configprops /actuator/configprops 提供有关应用程序的 @ConfigurationProperties 的beans env /actuator/env 提供有关应用程序的环境 flyway /actuator/flyway 提供有关由Flyway执行的数据库迁移的信息 health /actuator/health 提供有关应用程序运行状况的详细信息 heapdump /actuator/heapdump 提供了来自应用程序JVM的堆转储 threaddump /actuator/threaddump httptrace /actuator/httptrace 提供有关HTTP请求-响应交换的信息 info /actuator/info 提供有关应用程序的一般信息 integrationgraph /actuator/integrationgraph 公开一个包含所有SpringIntegration组件的图形 liquibase /actuator/liquibase 提供有关Liquibase应用的数据库更改集的信息 logfile /actuator/logfile 提供对应用程序日志文件内容的访问 loggers /actuator/loggers 提供对应用程序记录器及其级别配置的访问 mappings /actuator/mappings 提供有关应用程序的请求映射的信息 metrics /actuator/metrics 提供对应用程序度量的访问 prometheus /actuator/prometheus 提供以Prometheus服务器刮取所需的格式提供SpringBoot应用程序的度量 scheduledtasks /actuator/scheduledtasks 提供有关应用程序的计划任务的信息 sessions /actuator/sessions 提供有关由Spring会话管理的应用程序的HTTP会话的信息 shutdown /actuator/shutdown 用于关闭应用程序
2、启用端点
在默认 的情况下,除了shutdown都启用了(毕竟shutdown是关闭程序,这个的使用需要小心,以避免不慎使用或者被他人恶意使用)
启用shutdown (application.properties):
management.endpoint.shutdown.enabled = true
启用shutdown (application.yml):
management :
endpoint :
shutdown :
enabled : true
如果你不想所有端点都开启,只想开启自己想开启的端点,那么就使用下面这种方式:
(application.properties)
management.endpoints.enabled-by-default = false
【相关描述:Whether to enable or disable all endpoints by default】
【意为:默认情况下是启用还是禁用所有端点】
【此处选择false,则默认禁用所有端点】
management.endpoint.beans.enabled = true
【然后自己选择开启的端点,如开启beans】
3、暴露端点
因为端点可能包含敏感信息,因此应该仔细考虑何时公开它们。 如果要更改公开的端点,可以使用 include 和 exclude 属性。 ①上图详情:端点可以设置对外暴露不暴露,默认情况下jmx全暴露,web只默认暴露info,health
·默认情况下的配置如下(application.properties):
management.endpoints.jmx.exposure.include = *
【这个配置即使不在文件中说明,也是生效的,因为它是默认的配置】
·如果只想暴露部分端点,如health和info端点,则使用这条配置即可:
management.endpoints.jmx.exposure.include = health,info
·又或者只想把部分端点不暴露,如env和beans端点,则使用这两条配置即可:
management.endpoints.web.exposure.include = *
management.endpoints.web.exposure.exclude = env,beans
注意:在官方文档中有一条提示—— * 在YAML中具有特殊意义,因此,如果希望include (或exclude)所有端点,请确保添加引号,如以下示例所示:
management :
endpoints :
web :
exposure :
include : "*"