SpringBoot Management梳理

503 阅读1分钟

Spring Boot的管理端(Management Endpoints)是Spring Boot Actuator提供的一组用于监控和管理应用程序的端点。这些端点可以用于获取应用程序的运行信息、健康状况、metrics等。

下是一些常用的管理端点:

  1. /health:显示应用程序的健康信息,包括数据库、缓存和其他依赖服务的健康情况。
  2. /info:显示定义的应用程序信息。
  3. /metrics:显示应用程序的metrics信息,比如内存使用、请求数、响应时间等。
  4. /logfile:提供日志文件的内容,如果日志文件是可访问的。
  5. /env:显示所有环境变量。
  6. /beans:显示应用程序中所有Spring Bean的详细信息。
  7. /mappings:显示所有@RequestMapping的URL路径。
  8. /trace:显示最近的HTTP请求详情。
  9. /heapdump:导出应用程序的堆内存快照。

添加maven依赖:

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

yml配置:

management:
  endpoints:
    web:
      exposure:
        include: '*'

默认用 http://localhost:port/actuator 查看所有公开的端点

management.endpoints.web.exposure.include.health 和 management.endpoint.health 区别:

  1. management.endpoints.web.exposure.include.health: 表示 哪些端点应该被暴露出来
  2. management.endpoint.health: 允许你更深入地配置和控制 health 端点的行为
  3. management.endpoints.web.exposure.include 中如果没有health,management.endpoint.health的配置就不起作用