1、Actuator简介
- 每一个微服务在云上部署以后,我们都需要对其进行监控、追踪、审计、控制等。
- SpringBoot就抽取了Actuator场景,使得我们每个微服务快速引用即可获得生产级别的应用监控、审计等功能。
- springboot1.0与springboot2.0版本存在很大区别,2.0版本支持内容更多。
2、Actuator使用
(1)引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
(2)浏览器访问:http://localhost:8080/actuator/**
-
通过以上访问,可以知道提供了那些可以监控的指标(health,info,…);
-
提供有jmx和web两种访问方式,在浏览器模式中,大多数监控指标为关闭状态,需要配置手动开启。
management:
endpoints:#配置所有端点
enabled-by-default: true #暴露所有端点信息
web:
exposure:
include: '*' #以web方式暴露
endpoint: #配置指定端点
health:
show-details: always
- 可以使用以下指标进行监控测试
语法:
http://localhost:8080/actuator/endpointName/detailPath
项目路径+actuator+指标名称+具体路径
http://localhost:8080/actuator/beans //有哪些beans
http://localhost:8080/actuator/configprops //有哪些配置
http://localhost:8080/actuator/metrics //指标:内存、数量等
//metrics 指标监控具体值
http://localhost:8080/actuator/metrics/jvm.gc.pause
http://localhost:8080/actuator/endpointName/detailPath
......
3、Actuator Endpoint
(1)最常用的Endpoint
- Health:监控状况,健康检查
- Metrics:运行时指标
- Loggers:日志记录
(2)常见监控指标
id | 描述 |
---|---|
beans | beans 显示应用程序中所有Spring Bean的完整列表。 |
caches | 暴露可用的缓存 |
conditions | 显示自动配置的所有条件信息,包括匹配或不匹配的原因。 |
configprops | 显示所有@ConfigurationProperties。 |
health | health 显示应用程序运行状况信息。 |
info | 显示应用程序信息 |
metrics | 显示当前应用程序的“指标”信息 |
mappings | 显示所有@RequestMapping路径列表。 |
(3)管理开关
可以关闭全部端点,选择需要监控的端点开启
management:
endpoints:
enabled-by-default: false
endpoint:
beans:
enabled: true
health:
enabled: true
HTTP:默认只暴露health和info Endpoint
JMX:默认暴露所有Endpoint
除过health和info,剩下的Endpoint都应该进行保护访问。如果引入SpringSecurity,则会默认配置安全访问规则。