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

如何编写MQL查询获取标签值?(谷歌云监控+Grafana场景)

使用MQL查询提取标签值(谷歌云监控数据源)

针对你提供的db2_prometheus_adapter_info指标,要在Grafana中通过谷歌云监控的MQL查询提取app_state标签的取值,可根据不同需求使用以下两种查询方式:

场景1:获取当前时间序列的app_state标签值(单个值)

当你需要展示指标当前对应的app_state取值时,使用以下查询:

fetch prometheus_target
| metric 'prometheus.googleapis.com/db2_prometheus_adapter_info/gauge'
| last_point
| project app_state

各部分说明:

  • fetch prometheus_target:指定从谷歌云监控中存储Prometheus数据的资源类型中查询
  • metric 'prometheus.googleapis.com/db2_prometheus_adapter_info/gauge':匹配导入后的完整指标名(Prometheus gauge指标导入GCM后会自动添加前缀和后缀)
  • last_point:获取指标最新的时间点数据,确保返回当前的标签状态
  • project app_state:仅输出app_state标签的取值列

场景2:获取该指标所有可能的app_state标签取值(多个值)

如果需要查看该指标历史或当前存在的所有app_state唯一取值,使用以下查询:

fetch prometheus_target
| metric 'prometheus.googleapis.com/db2_prometheus_adapter_info/gauge'
| distinct app_state
  • distinct app_state:提取app_state标签的所有不重复取值

注意事项

  1. 确认指标全名:可在谷歌云监控控制台的「指标浏览器」中搜索原指标名,找到对应的完整指标路径
  2. 调整资源类型:如果你的指标不是通过Prometheus导入,而是自定义指标,需将fetch prometheus_target替换为对应的资源类型(如fetch global或其他自定义资源类型)
  3. Grafana面板配置:将上述MQL查询填入谷歌云监控数据源的查询框后,可选择文本面板(展示单个值)或表格面板(展示多个值)来呈现结果

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 08:42:15