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

如何在Grafana面板标题或Y轴中添加标签值?——Prometheus+snmp_exporter存储监控场景

Grafana面板标题/Y轴添加标签值(含SNMP存储监控场景)

我来帮你搞定这个Grafana和Prometheus监控的问题,刚好我对这块熟得很😉

一、针对你的SNMP存储监控场景(添加$hrStorageDescr到标题/Y轴)

你已经用$hrStorageIndex作为重复变量生成多个存储面板,现在要把对应的hrStorageDescr(比如"/"、"Physical memory")加到标题或Y轴,核心是让Grafana能拿到每个hrStorageIndex对应的hrStorageDescr标签值,具体步骤如下:

1. 确保查询结果包含hrStorageDescr标签

因为hrStorageDescr是单独的指标,需要把它的标签关联到存储使用率的查询结果里。比如你用来计算存储使用率的PromQL可以改成这样:

(
  hrStorageUsed{hrStorageIndex="$hrStorageIndex"} 
  * on(hrStorageIndex) group_left(hrStorageDescr) hrStorageDescr
) 
* 
hrStorageAllocationUnits{hrStorageIndex="$hrStorageIndex"} 
/ 
(
  hrStorageSize{hrStorageIndex="$hrStorageIndex"} 
  * hrStorageAllocationUnits{hrStorageIndex="$hrStorageIndex"}
) 
* 100

这里用on(hrStorageIndex) group_left(hrStorageDescr)把hrStorageDescr的标签合并到hrStorageUsed的结果中,这样查询结果就会带上hrStorageDescr标签了。

2. 配置面板标题

进入面板编辑界面,在Title输入框里直接引用标签:

存储使用率监控 - {{hrStorageDescr}}

这样每个重复生成的面板标题都会自动显示对应的存储描述(比如“存储使用率监控 - /”、“存储使用率监控 - Physical memory”)。

3. 配置Y轴标签

在面板的Axes设置里找到Y轴的Label字段,输入:

{{hrStorageDescr}} 使用率 (%)

这样Y轴就会显示对应的存储描述,让图表更直观。

二、通用场景:Grafana标题/Y轴添加标签值的方法

不管是什么监控场景,核心都是让Grafana能获取到你需要的标签或变量值,然后通过插值语法引用:

1. 基础引用规则

  • 引用查询结果中的标签:用双大括号包裹标签名,比如{{instance}}、{{job}}
  • 引用Grafana变量:用双大括号加$前缀,比如{{$host}}、{{$service}}

2. 确保标签/变量可被引用

  • 如果标签不在当前查询结果里:用PromQL的group_left/group_right关联其他指标的标签(就像上面SNMP场景的做法),或者在变量设置中直接查询标签值。
  • 如果是变量:提前在Dashboard的Variables设置中定义好变量(比如通过PromQL查询label_values(metric_name, label_name)生成变量选项)。

3. 示例场景

  • 面板标题:{{$instance}} - CPU负载监控(引用实例变量)
  • Y轴标签:{{job}} 内存使用量 (MB)(引用job标签)

附:你提供的SNMP采集指标参考

HELP hrStorageAllocationUnits The size, in bytes, of the data objects allocated from this pool - 1.3.6.1.2.1.25.2.3.1.4
TYPE hrStorageAllocationUnits gauge
hrStorageAllocationUnits{hrStorageIndex="1"} 1024
hrStorageAllocationUnits{hrStorageIndex="10"} 1024
hrStorageAllocationUnits{hrStorageIndex="3"} 1024
hrStorageAllocationUnits{hrStorageIndex="31"} 1024
hrStorageAllocationUnits{hrStorageIndex="32"} 4096
hrStorageAllocationUnits{hrStorageIndex="33"} 1024
hrStorageAllocationUnits{hrStorageIndex="34"} 4096
hrStorageAllocationUnits{hrStorageIndex="6"} 1024
hrStorageAllocationUnits{hrStorageIndex="7"} 1024
hrStorageAllocationUnits{hrStorageIndex="8"} 1024
HELP hrStorageDescr A description of the type and instance of the storage described by this entry. - 1.3.6.1.2.1.25.2.3.1.3
TYPE hrStorageDescr gauge
hrStorageDescr{hrStorageDescr="/",hrStorageIndex="31"} 1
hrStorageDescr{hrStorageDescr="/etc/log",hrStorageIndex="34"} 1
hrStorageDescr{hrStorageDescr="/etc/mnt",hrStorageIndex="33"} 1
hrStorageDescr{hrStorageDescr="/sys/fs/cgroup/cpuset",hrStorageIndex="32"} 1
hrStorageDescr{hrStorageDescr="Cached memory",hrStorageIndex="7"} 1
hrStorageDescr{hrStorageDescr="Memory buffers",hrStorageIndex="6"} 1
hrStorageDescr{hrStorageDescr="Physical memory",hrStorageIndex="1"} 1
hrStorageDescr{hrStorageDescr="Shared memory",hrStorageIndex="8"} 1
hrStorageDescr{hrStorageDescr="Swap space",hrStorageIndex="10"} 1
hrStorageDescr{hrStorageDescr="Virtual memory",hrStorageIndex="3"} 1
HELP hrStorageIndex A unique value for each logical storage area contained by the host. - 1.3.6.1.2.1.25.2.3.1.1
TYPE hrStorageIndex gauge
hrStorageIndex{hrStorageIndex="1"} 1
hrStorageIndex{hrStorageIndex="10"} 10
hrStorageIndex{hrStorageIndex="3"} 3
hrStorageIndex{hrStorageIndex="31"} 31
hrStorageIndex{hrStorageIndex="32"} 32
hrStorageIndex{hrStorageIndex="33"} 33
hrStorageIndex{hrStorageIndex="34"} 34
hrStorageIndex{hrStorageIndex="6"} 6
hrStorageIndex{hrStorageIndex="7"} 7
hrStorageIndex{hrStorageIndex="8"} 8
HELP hrStorageSize The size of the storage represented by this entry, in units of hrStorageAllocationUnits - 1.3.6.1.2.1.25.2.3.1.5
TYPE hrStorageSize gauge
hrStorageSize{hrStorageIndex="1"} 947676
hrStorageSize{hrStorageIndex="10"} 0
hrStorageSize{hrStorageIndex="3"} 947676
hrStorageSize{hrStorageIndex="31"} 115157
hrStorageSize{hrStorageIndex="32"} 0
hrStorageSize{hrStorageIndex="33"} 45478
hrStorageSize{hrStorageIndex="34"} 3.746398e+06
hrStorageSize{hrStorageIndex="6"} 947676
hrStorageSize{hrStorageIndex="7"} 177976
hrStorageSize{hrStorageIndex="8"} 10836
HELP hrStorageType The type of storage represented by this entry. - 1.3.6.1.2.1.25.2.3.1.2
TYPE hrStorageType gauge
hrStorageType{hrStorageIndex="1",hrStorageType="1.3.6.1.2.1.25.2.1.2"} 1
hrStorageType{hrStorageIndex="10",hrStorageType="1.3.6.1.2.1.25.2.1.3"} 1
hrStorageType{hrStorageIndex="3",hrStorageType="1.3.6.1.2.1.25.2.1.3"} 1
hrStorageType{hrStorageIndex="31",hrStorageType="1.3.6.1.2.1.25.2.1.4"} 1
hrStorageType{hrStorageIndex="32",hrStorageType="1.3.6.1.2.1.25.2.1.4"} 1
hrStorageType{hrStorageIndex="33",hrStorageType="1.3.6.1.2.1.25.2.1.4"} 1
hrStorageType{hrStorageIndex="34",hrStorageType="1.3.6.1.2.1.25.2.1.4"} 1
hrStorageType{hrStorageIndex="6",hrStorageType="1.3.6.1.2.1.25.2.1.1"} 1
hrStorageType{hrStorageIndex="7",hrStorageType="1.3.6.1.2.1.25.2.1.1"} 1
hrStorageType{hrStorageIndex="8",hrStorageType="1.3.6.1.2.1.25.2.1.1"} 1
HELP hrStorageUsed The amount of the storage represented by this entry that is allocated, in units of hrStorageAllocationUnits. - 1.3.6.1.2.1.25.2.3.1.6
TYPE hrStorageUsed gauge
hrStorageUsed{hrStorageIndex="1"} 803248
hrStorageUsed{hrStorageIndex="10"} 0
hrStorageUsed{hrStorageIndex="3"} 803248
hrStorageUsed{hrStorageIndex="31"} 57812
hrStorageUsed{hrStorageIndex="32"} 0
hrStorageUsed{hrStorageIndex="33"} 2172
hrStorageUsed{hrStorageIndex="34"} 2.825416e+06
hrStorageUsed{hrStorageIndex="6"} 69612
hrStorageUsed{hrStorageIndex="7"} 177976
hrStorageUsed{hrStorageIndex="8"} 10836

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.30 06:47:40