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

监控数据库查询调用性能:Grafana中Gauge与Summary查询及绘图

Spring Boot+Micrometer+Prometheus+Grafana 监控指南(针对Gauge/Summary指标)

一、}后面数值的含义

这部分是指标的实时样本值,不同类型指标的数值意义不一样:

  • 对于你的spring_data_repository_invocations_seconds_max(Gauge类型):0.004128917代表当前记录的InfoRepository.save方法成功调用的最大耗时,单位是秒(约4.1毫秒)。
  • 对于spring_data_repository_invocations_seconds(Summary类型):
    • 42998.0是_count后缀,代表该方法成功调用的总次数;
    • 53.740906851是_sum后缀,代表该方法所有成功调用的总耗时(秒)。

二、Gauge类型指标的查询与绘图

查询方法

Gauge是瞬时值指标,直接用指标名+标签过滤就能查询,比如:

spring_data_repository_invocations_seconds_max{application="customer", exception="None", state="SUCCESS"}

如果想监控所有repository方法的最大耗时,去掉method和repository标签即可。

绘图(时序图)

  1. 在Grafana里新建面板,选择Time series(时序图)类型;
  2. 在查询编辑器里输入上面的PromQL语句;
  3. 调整图例(比如用{{method}}显示方法名),设置Y轴单位为seconds或milliseconds;
  4. 保存面板,就能看到最大耗时随时间的变化趋势,用来排查是否有突发的慢调用。

三、Summary类型指标的查询与绘图

Summary会生成两个子指标:_count(调用次数)和_sum(总耗时),可以组合出更有用的监控数据。

常用查询语句

  1. 查看总调用次数:
spring_data_repository_invocations_seconds_count{application="customer", state="SUCCESS"}
  1. 计算每秒调用量(QPS):用rate函数统计最近1分钟的平均每秒调用数:
rate(spring_data_repository_invocations_seconds_count{application="customer", state="SUCCESS"}[1m])
  1. 计算平均耗时:总耗时除以总调用次数:
spring_data_repository_invocations_seconds_sum{application="customer", state="SUCCESS"} 
/ 
spring_data_repository_invocations_seconds_count{application="customer", state="SUCCESS"}

绘图方案

1. 时序图(监控趋势)

  • 用QPS的查询语句,绘制时序图,看调用量的波动情况,判断是否有流量峰值或异常下跌;
  • 用平均耗时的查询语句,绘制时序图,跟踪接口性能的变化趋势。

2. 仪表盘(展示关键指标)

  1. 新建面板,选择Stat(统计面板)或Gauge(仪表盘)类型;
  2. 分别输入总调用次数、当前平均耗时、最大耗时的查询语句;
  3. 设置面板的显示样式(比如数值颜色、单位),把关键指标集中展示在一个仪表盘里,快速掌握应用的整体性能情况。

内容的提问来源于stack exchange,提问作者dead programmer

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 14:43:21