Spring Boot下Actuator配置与监控

2021-04-27 567 0

介绍

Spring Boot Actuator可以帮助你监控和管理Spring Boot应用,比如健康检查、审计、统计和HTTP追踪等。所有的这些特性可以通过JMX或者HTTP endpoints来获得。

Actuator同时还可以与外部应用监控系统整合,比如 Prometheus, Graphite, DataDog, Influx, Wavefront, New Relic等。这些系统提供了非常好的仪表盘、图标、分析和告警等功能,使得你可以通过统一的接口轻松的监控和管理你的应用

https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#production-ready

项目中增加依赖

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

暴露全部endPoint配置

management:
  endpoints:
    #修改全局endpoint默认设置
    enabled-by-default: true
    #暴露EndPoint,有jmx和web两种方式,exclude的优先级高于include
    jmx:
      exposure:
        #exclude: '*'
        include: '*'
    web:
      exposure:
        include: "*"

暴露指定endPoint配置

management:
  endpoints:
    #修改全局endpoint默认设置
    enabled-by-default: false
    #暴露EndPoint,有jmx和web两种方式,exclude的优先级高于include
    jmx:
      exposure:
        #exclude: '*'
        include: '*'
    web:
      exposure:
        include: "*"
  #具体endpoint配置,如果全局enabled-by-default满足要求,就不要每个都配
  endpoint:
    info: # 、显示任意的应用信息,默认开启
      enabled: true
    health: # 显示健康信息,默认开启
      enabled: true
      #never(默认)、when-authorized、always
      show-details: always
    auditevents: # 显示当前引用程序的审计事件信息,默认开启
      enabled: true
    cache:
      time-to-live: 10s # 配置端点缓存响应的时间
    beans: # 、显示一个应用中所有 Spring Beans 的完整列表,默认开启
      enabled: true
    conditions: # 显示配置类和自动配置类的状态及它们被应用和未被应用的原因,默认开启
      enabled: true
    configprops: # 显示一个所有@ConfigurationProperties的集合列表,默认开启
      enabled: true
    env: # 显示来自Spring的 ConfigurableEnvironment的属性,默认开启
      enabled: true
    flyway: # 显示数据库迁移路径,如果有的话,默认开启
      enabled: true
    liquibase: # 展示任何Liquibase数据库迁移路径,如果有的话,默认开启
      enabled: true
    metrics: #展示当前应用的metrics信息,默认开启
      enabled: true
    mappings: #显示一个所有@RequestMapping路径的集合列表,默认开启
      enabled: true
    scheduledtasks: #显示应用程序中的计划任务,默认开启
      enabled: true
    sessions: #允许从Spring会话支持的会话存储中检索和删除(retrieval and deletion)用户会话。使用Spring Session对反应性Web应用程序的支持时不可用。默认开启。
      enabled: true
    shutdown: #允许应用以优雅的方式关闭,默认关闭
      enabled: true
    threaddump: #执行一个线程dump
      enabled: true
    # web 应用时可以使用以下端点
    heapdump: # 返回一个GZip压缩的hprof堆dump文件,默认开启
      enabled: true
    jolokia: # 通过HTTP暴露JMX beans(当Jolokia在类路径上时,WebFlux不可用),默认开启
      enabled: true
    logfile: # 返回日志文件内容(如果设置了logging.file或logging.path属性的话),支持使用HTTP Range头接收日志文件内容的部分信息,默认开启
      enabled: true
    prometheus: #以可以被Prometheus服务器抓取的格式显示metrics信息,默认开启
      enabled: true

web效果

file

file

相关文章

线上PostgreSQL锁表故障分析
PostgreSQL创建外部表场景及使用
vim常用命令
navicat15 for linux桌面的破解激活
快速实现通用的办公文档在线预览方案
自建流媒体服务,快速打造自己的短视频点播平台

发布评论