1. 前言
本文是<< Spring Boot 实战 >>和<< Java EE开发的颠覆者 Spring Boot 实战 >>的学习笔记, 以便自己查阅.
Sprng Boot 2 actuator变动加大, 网上很多资料都都已经过期, 所以记录一下.
2. 配置
在 application.properties 配置文件, actuator 的设置项 management.endpoints(设置 actuator 全局级的属性) 和 management.endpoint(设置 具体endpoint 属性) 开头.
2.1 全局级的控制
1 | #定制管理功能的 port, 如果端口为 -1 代表不暴露管理功能 over HTTP |
2.2 endpoint 级别的控制
所有的endpoint都有 enabled 属性, 可以按需开启或关闭特定端点.
1 | #启用 shutdown |
2.3 health端点配置
1 | management.endpoint.health.enabled=true |
2.4 actuator 缺省的设置
缺省 actuator 的根路径为 /actuator
缺省仅开放 health 和 info, 其他都不开放.
有些 endpoint 是GET, 有些是POST方法, 比如 health 为GET, shutdown 为 POST, 从SpringBoot程序启动日志中,可以看出到底有哪些endpoint被开启.
2.5 endpoint 清单
actuator 支持的所有 endpoint, 可以查官网
https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html
下面是一些重要的端点,(以访问路径列出):
1 | /actuator: actuator 严格地说不能算 endpoint, /actuator 返回要给 endpoint 的清单. |
3. 使用
在pom文件导入依赖即可.
1 | <dependencies> |
3.1 其他说明
actuator的UI显示不好,所以网上有很多结合actuator使用的UI界面. 不过日常一般也不会去用这个actuator, 只是spring cloud里面会有需要.
4. 参考链接
<< Spring Boot 实战 >>(Craig Walls 著, 丁雪丰 译)
<< Java EE开发的颠覆者 Spring Boot 实战 >>
SpringBoot系列: Actuator监控