相关推荐recommended
SpringbootActuator监控与管理
作者:mmseoamin日期:2024-01-18

Actuator监控与管理

准备条件

  • idea IntelliJ IDEA 2019.3 (Ultimate Edition)
  • **SpringBoot '**2.2.2.RELEASE’
  • Java version 1.8

    在微服务架构中,将单体系统拆分为多个独立的服务应用使得系统变得更加灵活和可扩展,但也带来了运维上的挑战。随着应用数量增多,监控和维护这些服务变得更加复杂。为了解决这些挑战,需要建立一套自动化的监控和运维机制。

    在使用Spring Boot作为微服务框架时,spring-boot-starter-actuator模块提供了一系列用于监控的端点,这些端点允许获取应用程序的各种信息,并且可以通过配置和扩展实现自定义监控需求。这个模块的使用可以减少监控系统在采集应用指标时的开发工作量。

    spring-boot-starter-actuator模块提供了一些常用的端点,比如:

    1. /actuator/health:提供应用程序的健康状态信息,可以检查应用程序是否正常运行。
    2. /actuator/info:提供关于应用程序的自定义信息。
    3. /actuator/metrics:展示应用程序的各种度量指标,比如内存使用情况、线程池信息等。
    4. ** /actuator/env**:展示应用程序的环境变量信息。
    5. ** /actuator/beans**:展示应用程序中所有的Spring Beans信息。

    此外,Spring Cloud对spring-boot-starter-actuator模块进行了扩展,以支持与微服务相关的一些功能,比如与Eureka整合时,会在/actuator/health端点中添加更多健康检查信息。

    虽然spring-boot-starter-actuator提供了很多功能,但有时候也需要根据特定需求做一些扩展或定制。可以通过自定义端点、配置指标收集、拦截器等方式来满足特定的监控需求。

    总的来说,spring-boot-starter-actuator模块为微服务架构提供了一套方便且强大的监控机制,能够大大简化监控系统对应用指标收集的工作,同时也提供了扩展机制,允许根据特定需求进行定制。

    快速入门

    1. spring boot项目中引入 spring-boot-starter-actuator 模块功能,只需要在pom.xml的 dependency 节点中。
    
        org.springframework.boot
        spring-boot-starter-actuator
    
    
    1. application.yaml配置显示信息添加配置信息
    management:
      endpoints:
        enabled: true
        web:
          base-path: /actuator
          exposure:
            include: "*"
      endpoint:
        health:
          show-details: always
    

    重新启动应用。此时我们在控制台中可以看到如下输出

    SpringbootActuator监控与管理,在这里插入图片描述,第1张- http://localhost:8080/actuator显示所有的接口