- 引言
在当前的微服务架构方式下,我们会有很多的服务部署在不同的机器上,相互是通过服务调用的方式进行交互,一个完整的业务流程中间会经过很多个微服务的处理和传递,那么,如何能知道每个服务的健康状况就显得尤为重要。
万幸的是 Spring Boot 为我们提供了监控模块 Spring Boot Actuator ,本篇文章将和大家一起探讨一些 Spring Boot Actuator 一些常见用法方便我们在日常的使用中对我们的微服务进行监控治理。
Spring Boot Actuator 帮我们实现了对程序内部运行情况监控,比如监控状况、Bean加载情况、环境变量、日志信息、线程信息等。
- Actuator 的使用
2.1 工程依赖
使用 Spring Boot Actuator 需要加入如下依赖:
代码清单:spring-boot-actuator/src/main/resources/application.yml
server:
port: 8080
info:
app:
name: spring-boot-actuator
version: 1.0.0
spring:
security:
user:
name: admin
password: adminCOPY
现在先启动工程,打开浏览器访问:http://localhost:8080/actuator ,可以看到页面显示如下 json :
{
“_links”:{
“self”:{
“href”:“http://localhost:8080/actuator”,
“templated”:false
},
“health”:{
“href”:“http://localhost:8080/actuator/health”,
“templated”:false
},
“health-component-instance”:{
“href”:“http://localhost:8080/actuator/health/{component}/{instance}”,
“templated”:true
},
“health-component”:{
“href”:“http://localhost:8080/actuator/health/{component}”,
“templated”:true
},
“info”:{
“href”:“http://localhost:8080/actuator/info”,
“templated”:false
}
}
}COPY
这些是默认支持的链接,只有:
/actuator
/actuator/health
/health/{component}/{instance}
/health/{component}
/actuator/infoCOPY
我们可以在配置文件 application.yml 中增加配置来开启更多的监控信息:
management:
endpoints:
web:
exposure:
include: ‘*’
base-path: /monitor
endpoint:
health:
show-details: always
shutdown: