1 概述

  • 通过引入spring-boot-starter-actuator,可以使用SpringBoot为我们提供的准生产环境下的应用监控和管理功能。我们可以通过HTTP、JMX、SSH协议来进行操作,自动得到审计、健康以及指标信息等。
  • 监控和管理端点: | 端点名 | 描述 | | —- | —- | | autoconfig | 所有自动配置信息 | | auditevents | 审计事件 | | beans | 所有Bean的信息 | | configprops | 所有配置属性 | | dump | 线程状态信息 | | env | 当前环境信息 | | health | 应用健康状况 | | info | 当前应用信息 | | metrics | 应用的各项指标 | | mappings | 应用@RequestMapping映射路径 | | shutdown | 关闭当前应用(默认关闭) | | trace | 追踪信息(最新的http请求) |

2 SpringBoot整合actuator

SpringBoot的版本是1.5.12.RELEASE

2.1 引入spring-boot-starter-actuator的Maven坐标

  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-actuator</artifactId>
  4. </dependency>
  5. <dependency>
  6. <groupId>org.springframework.boot</groupId>
  7. <artifactId>spring-boot-starter-web</artifactId>
  8. </dependency>
  9. <dependency>
  10. <groupId>org.springframework.boot</groupId>
  11. <artifactId>spring-boot-devtools</artifactId>
  12. <scope>runtime</scope>
  13. <optional>true</optional>
  14. </dependency>
  15. <dependency>
  16. <groupId>org.springframework.boot</groupId>
  17. <artifactId>spring-boot-starter-test</artifactId>
  18. <scope>test</scope>
  19. </dependency>

2.2 修改application.propreties

  1. # 关闭安全
  2. management.security.enabled=false
  3. #远程关闭应用
  4. endpoints.shutdown.enabled=true
  5. info.app.id=hello
  6. info.app.version=1.0

2.3 测试

3 定制端点

  • 定制端点一般通过endpoints+端点名+属性名来设置。
  1. # 关闭安全
  2. management.security.enabled=false
  3. #远程关闭应用
  4. endpoints.shutdown.enabled=true
  5. info.app.id=hello
  6. info.app.version=1.0
  7. # 修改端点
  8. #endpoints.beans.id=mybean
  9. #endpoints.beans.path=/bean
  10. # 禁用端点
  11. #endpoints.beans.enabled=false
  12. # 关闭所有的端点,并启用某个端点
  13. #endpoints.enabled=false
  14. #endpoints.beans.enabled=true
  15. # 定制所有端点的根路径
  16. management.context-path=/manage
  17. # 定制所有端点的端口,如果是-1,就表示不能访问
  18. management.port=8081