1、Actuator 帮助你在应用程序生产环境时监视和管理应用程序。可以使用HTTP的各种请求来监管,审计,收集应用的运行情况。
2、Maven中增加以下依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
3、通过在appliction.properties
或appliction.yml
中暴露actuator
的监控接口
management.endpoints.web.exposure.include=*,hystrix.stream
4、其中actuator自带的监控接口包括:
URL | 作用 |
---|---|
/actuator/health | 健康检查 |
/actuator/beans | 查看容器中的所有bean |
/actuator/mapping | 查看Web的URL映射 |
/actuator/env | 查看环境信息 |
/actuator/dump | 查看活动线程 |
/actuator/info | 查看定制信息 |
/actuator/metrics | 查看内存、CPU核心等系统参数 |
/actuator/trace | 查看用户请求信息 |
/actuator/loggers | 查看日志 |
5、如何解禁 Endpoint
默认
- /actuator/health 和 /actuator/info 可 Web 访问
这里按需配置就好了哈。比如我需要健康检查和查看环境信息
- management.endpoints.web.exposure.include=health,env
解禁所有 Endpoint
在appliction.properties
或appliction.yml
中
- management.endpoints.web.exposure.include=*
6、生产环境需谨慎
尽量不要生产环境发布过多的 Endpoints,因为里面含有像 shutdown 的 Endpoint,其实是可以关闭你的系统的。