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

如何简化Grafana面板中Kubernetes节点存储指标的图例

解决Grafana图例冗余问题的两种方法

方法一:直接在Grafana中配置图例模板

这是最快捷的方式,无需修改Prometheus查询:

  1. 进入面板编辑模式,找到对应的Prometheus查询项
  2. 在查询项右侧找到Legend输入框(默认可能显示{{instance}}或其他变量)
  3. 输入以下模板:
    fstype="{{fstype}}" instance="{{instance}}" mountpoint="{{mountpoint}}"
    
  4. 保存面板后,图例就会精确显示你需要的三个标签内容,格式完全符合要求。

方法二:在Prometheus查询中过滤标签

如果希望从数据源层面就只返回需要的标签,可以修改查询语句:

  • 若你的Prometheus版本≥v2.27,使用keep_labels函数直接保留指定标签:
    keep_labels(
      (1 - (node_filesystem_avail_bytes{fstype!="rootfs", mountpoint="/"} / node_filesystem_size_bytes{fstype!="rootfs", mountpoint="/"})) * 100,
      "fstype", "instance", "mountpoint"
    )
    
  • 若版本较低,改用drop_labels去掉所有不需要的标签(需列出实际冗余标签名):
    drop_labels(
      (1 - (node_filesystem_avail_bytes{fstype!="rootfs", mountpoint="/"} / node_filesystem_size_bytes{fstype!="rootfs", mountpoint="/"})) * 100,
      "job", "namespace", "pod", "service" # 替换为你实际的冗余标签
    )
    

修改后,Prometheus返回的结果仅包含你需要的标签,Grafana图例自然会简洁显示。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 21:15:10