• Spring Boot 集成 Actuator 监控工具


    Spring Boot 集成 Actuator 监控工具

    本章节将介绍 Spring Boot 集成 Actuator 监控工具。

    🤖 Spring Boot 2.x 实践案例(代码仓库)

    介绍

    Spring Boot Actuator 提供了对 SpringBoot 应用程序(可以是生产环境)监视和管理的能力, 可以选择通过使用 HTTP Endpoint 或使用 JMX 来管理和监控 SpringBoot 应用程序。

    Spring Boot Actuator 允许通过 Endpoints 对 Spring Boot 进行监控和交互。

    Spring Boot 内置的 Endpoint 包括(两种Endpoint: WEB和JMX,WEB方式考虑到安全性默认只开启了/health):

    IDJMXWebEndpoint功能描述
    auditeventsYesNo暴露当前应用的audit events (依赖AuditEventRepository)
    beansYesNoSpring中所有Beans
    cachesYesNo暴露可用的缓存
    conditionsYesNo展示configuration 和auto-configuration类中解析的condition,并展示是否匹配的信息.
    configpropsYesNo展示所有的@ConfigurationProperties
    envYesNo展示环境变量,来源于ConfigurableEnvironment
    flywayYesNoflyway数据迁移信息(依赖Flyway)
    healthYesYes展示应用的健康信息
    heapdumpN/ANoweb应用时)hprof 堆的dump文件(依赖HotSpot JVM)
    httptraceYesNo展示HTTP trace信息, 默认展示前100个(依赖HttpTraceRepository)
    infoYesNo应用信息
    integrationgraphYesNo展示spring集成信息(依赖spring-integration-core)
    jolokiaN/ANoweb应用时)通过HTTP暴露JMX beans(依赖jolokia-core)
    logfileN/ANoweb应用时)如果配置了logging.file.name 或者 logging.file.path,展示logfile内容
    loggersYesNo展示或者配置loggers,比如修改日志的等级
    liquibaseYesNoLiquibase 数据迁移信息(依赖Liquibase)
    metricsYesNo指标信息
    mappingsYesNo@RequestMapping映射路径
    prometheusN/ANoweb应用时)向prometheus暴露监控信息(依赖micrometer-registry-prometheus)
    quartzYesNo展示 quartz任务信息
    scheduledtasksYesNo展示Spring Scheduled 任务信息
    sessionsYesNosession信息
    shutdownYesNo关闭应用
    startupYesNo展示ApplicationStartup的startup步骤的数据(依赖通在SpringApplication配置BufferingApplicationStartup)
    threaddumpYesNo线程dump

    快速开始

    引入依赖

    >
        >org.springframework.boot>
        >spring-boot-starter-actuator>
    >
    

    配置文件

    management:
      endpoints:
        web:
          # 自定义管理端点路径
          base-path: /manage
          # 自定义端点
          exposure:
            include: "info,health,env,beans"
            # 启动所有端点
            # include: "*"
    

    上述配置只暴露info、health、env、beans四个endpoints,web可通过/manage/${endpoint}进行访问

    beans

    跨域访问

    management:
      endpoints:
        web:
          cors:
            allowed-origins: "https://example.com"
            allowed-methods: "GET,POST"
    

    获取Info信息

    spring-boot-maven-plugin中加入build-info, 编译成jar后运行,即可获取info:

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-maven-pluginartifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>build-infogoal>
                        goals>
                    execution>
                executions>
            plugin>
        plugins>
    build>
    
  • 相关阅读:
    有向图计数优化版原理及C++实现
    linux入门到精通-第三章-vi(vim)编辑器
    通达信接口的定义和实现
    Vue.js+Node.js全栈开发教程:Vue.js插值
    Oracle数据库使用PLSQL-Developer15导出导入Excel文件
    数据可视化工具调研
    第十九章 文件操作
    Java - 你真的明白单例模式怎么写了吗?
    java中final和finally和finalize的区别
    鲁棒局部均值分解 (RLMD)(Matlab代码实现)
  • 原文地址:https://blog.csdn.net/qq991658923/article/details/127112107