在生产环境中,须要实时或按期监控服务的可用性。Spring Boot的actuator(健康监控)功能提供了不少监控所需的接口,能够对应用系统进行配置查看、相关功能统计等。git
集成:github
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
若是使用HTTP调用的方式,还须要这个依赖:web
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
配置:spring
application.yml中指定监控的HTTP端口(若是不指定,则使用和Server相同的端口);指定去掉某项的检查(好比不监控health.mail):segmentfault
server: port: 8082 management: port: 54001 health: mail: enabled: false
使用:app
HTTP方法 | 路径 | 描述 | 鉴权 |
---|---|---|---|
GET | /autoconfig | 查看自动配置的使用状况 | true |
GET | /configprops | 查看配置属性,包括默认配置 | true |
GET | /beans | 查看bean及其关系列表 | true |
GET | /dump | 打印线程栈 | true |
GET | /env | 查看全部环境变量 | true |
GET | /env/{name} | 查看具体变量值 | true |
GET | /health | 查看应用健康指标 | false |
GET | /info | 查看应用信息(须要本身在application.properties里头添加信息,好比info.contact.email=easonjim@163.com) | false |
GET | /mappings | 查看全部url映射 | true |
GET | /metrics | 查看应用基本指标 | true |
GET | /metrics/{name} | 查看具体指标 | true |
POST | /shutdown | 关闭应用(要真正生效,得配置文件开启endpoints.shutdown.enabled: true) | true |
GET | /trace | 查看基本追踪信息 | true |
Maven示例:spring-boot
https://github.com/easonjim/spring-cloud-demo/tree/master/ZooKeeperurl
参考:spa
https://segmentfault.com/a/1190000004318360?_ea=568366.net