1: Spring Boot Actuator提供一系列HTTP端点来暴露项目信息,用来监控和管理项目,由于Spring Boot Actuator 2.x进行了重构,逻辑有变动,配置也不同
2:Spring Boot项目修改
2.1修改pom文件, 添加jar依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2.2 修改pom文件, 添加git信息插件依赖
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>2.2.4</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
</execution>
<execution>
<id>validate-the-git-infos</id>
<goals>
<goal>validateRevision</goal>
</goals>
</execution>
</executions>
<configuration>
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
</configuration>
</plugin>
二: actuator参数配置
-- 健康检查 spring-boot-starter-actuator-1.x 配置
# 打开actuator路径检索功能
endpoints.actuator.enabled = true
# 重定义根路径 (为了和actuator2.x版本一致, 2.0版本默认根路径 /actuator)
actuator.base.path = /actuator
endpoints.actuator.path = ${actuator.base.path}
# 关闭安全认证(所有的endpoint会暴露)
management.security.enabled = false
# 关闭所有的的endpoint
endpoints.enabled = false
# 启用health
endpoints.health.enabled = true
endpoints.health.path = ${actuator.base.path}/health
# 启用info
management.info.git.mode = full
endpoints.info.enabled = true
endpoints.info.path = ${actuator.base.path}/info
# 启用metrics
endpoints.metrics.enabled = true
endpoints.metrics.path = ${actuator.base.path}/metrics
-- 健康检查 spring-boot-starter-actuator-2.x 配置
# 显示git信息模式
management.info.git.mode = full
# 暴露的端点
management.endpoints.web.exposure.include = info,health,metrics
# 健康端点详情显示模式: never:不显示(默认);always:所有的; when-authorized:只展示给认证用户
management.endpoint.health.show-details = always
三: 校验是否成功
3.1 info端点校验
3.2 health 端点校验
3.3 metrics端点校验