springBootActuator
官方文档地址https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html
- 提供很多监控端点(endpoint)
1.使用,消费者,提供者都引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2.health
访问http://localhost:8088/actuator/health (springboot2版本路径中多了个actuator)
返回值:
{"status":"UP"}
UP:运行正常
Down
OUT_OF_SERVICE
UNKNOWN
只显示的概要情况,展示详情需要添加配置
- 1.5之前需要配置中添加
management.security.enabled=false来暴露所有端点
- 2.0之后
- management.endpoints.web.exposure.include=* 暴露所有端点,默认只暴露health和info端点(出于安全考虑)
-
# 启用端点 env management.endpoint.env.enabled=true # 暴露端点 env 配置多个,隔开 management.endpoints.web.exposure.include=env
暴露单个端点或者多个端点
或者添加security启动依赖,允许有actuator角色的用户访问所有端点
- management.endpoint.health.show-details=always#显示健康具体信息 默认不会显示详细信息
3.info
默认情况info访问后返回{}
在配置文件中配置
info:
app:
name: @project.artifactId@
encoding: @project.build.sourceEncoding@
java:
source: @java.version@
target: @java.version@