You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SpringBoot中@RefreshScope会生成哪些指标?能否在Prometheus/Grafana可视化?

SpringBoot中@RefreshScope的监控指标与可视化方案

一、@RefreshScope对应的监控指标

当在SpringBoot中结合Spring Cloud Config使用@RefreshScope时,通过Spring Boot Actuator + Micrometer会自动生成以下核心监控指标:

  • spring.cloud.refresh.refresh.count:累计触发配置刷新操作的总次数
  • spring.cloud.refresh.refresh.success.count:配置刷新成功的次数
  • spring.cloud.refresh.refresh.failure.count:配置刷新失败的次数
  • spring.cloud.refresh.scope.bean.count:当前处于@RefreshScope作用域下的Bean总数
  • spring.cloud.refresh.scope.refresh.count:@RefreshScope内Bean被刷新的累计次数
  • spring.cloud.refresh.refresh.duration:每次刷新操作的耗时指标(包含总和、最大值、最小值、百分位数等维度)

这些指标会自动注册到Micrometer的指标注册表中,只要开启Actuator的相关端点就能暴露。

二、Prometheus与Grafana的可视化支持

完全可以在Prometheus和Grafana中对这些指标进行可视化:

1. 指标采集配置

首先确保项目引入micrometer-registry-prometheus依赖,然后在配置文件中开启Actuator的prometheus和refresh端点:

management:
  endpoints:
    web:
      exposure:
        include: refresh, prometheus
  metrics:
    tags:
      application: ${spring.application.name}

Prometheus只需配置抓取该应用的/actuator/prometheus端点,就能自动采集上述所有@RefreshScope相关指标。

2. Grafana可视化实践

在Grafana中可以基于采集到的指标创建多种实用面板:

  • 配置刷新成功率面板:通过rate(spring.cloud.refresh.refresh.success.count[5m]) / rate(spring.cloud.refresh.refresh.count[5m])计算成功率,监控配置变更的稳定性
  • 刷新次数趋势图:用spring.cloud.refresh.refresh.count的增量绘制折线图,查看配置变更的频率
  • 刷新耗时分析:展示spring.cloud.refresh.refresh.duration的百分位数(如P95、P99),排查慢刷新问题
  • 作用域Bean数量监控:实时查看spring.cloud.refresh.scope.bean.count的变化,验证配置生效的Bean范围

内容的提问来源于stack exchange,提问作者Shridutt Kothari

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 18:32:22