如何更改Grafana视图中的图例

huangapple go评论58阅读模式
英文:

How to change the legend in a Grafana view

问题

我有一个Grafana视图面板,其中包含一个查询,用于返回Kubernetes集群中每个节点的信息。当显示图表时,图例显示了比所需信息更多的内容。查询如下:

(1 - (node_filesystem_avail_bytes{fstype!="rootfs", mountpoint="/"} / node_filesystem_size_bytes{fstype!="rootfs", mountpoint="/"})) * 100

如果我在Prometheus中运行此查询,会得到类似以下的结果(值已省略):

{container="node-exporter", device="/dev/mapper/ubuntu--vg-ubuntu--lv", endpoint="http-metrics", fstype="ext4", instance="172.20.32.10:9100", job="node-exporter", mountpoint="/", namespace="prometheus", pod="prometheus-prometheus-node-exporter-xvz7v", service="prometheus-prometheus-node-exporter"}
{container="node-exporter", device="/dev/mapper/ubuntu--vg-ubuntu--lv", endpoint="http-metrics", fstype="ext4", instance="172.20.32.11:9100", job="node-exporter", mountpoint="/", namespace="prometheus", pod="prometheus-prometheus-node-exporter-w8cqq", service="prometheus-prometheus-node-exporter"}
{container="node-exporter", device="/dev/mapper/ubuntu--vg-ubuntu--lv", endpoint="http-metrics", fstype="ext4", instance="172.20.32.12:9100", job="node-exporter", mountpoint="/", namespace="prometheus", pod="prometheus-prometheus-node-exporter-4wfhq", service="prometheus-prometheus-node-exporter"}
{container="node-exporter", device="/dev/mapper/ubuntu--vg-ubuntu--lv", endpoint="http-metrics", fstype="ext4", instance="172.20.32.13:9100", job="node-exporter", mountpoint="/", namespace="prometheus", pod="prometheus-prometheus-node-exporter-zfskj", service="prometheus-prometheus-node-exporter"}
{container="node-exporter", device="/dev/mapper/ubuntu--vg-ubuntu--lv", endpoint="http-metrics", fstype="ext4", instance="172.20.32.15:9100", job="node-exporter", mountpoint="/", namespace="prometheus", pod="prometheus-prometheus-node-exporter-cllnv", service="prometheus-prometheus-node-exporter"}

这也是填充图表图例的内容,使其变得非常长,并且比所需的要冗长。图例中的每个项目都是与查询中的度量标签相关联的所有标签的集合。

我希望能够简化此信息,以便图例中只显示人们关心的标签。例如,对于此图表,我希望显示:

fstype="ext4" instance="172.20.32.10" mountpoint="/"
fstype="ext4" instance="172.20.32.11" mountpoint="/"
fstype="ext4" instance="172.20.32.12" mountpoint="/"
fstype="ext4" instance="172.20.32.13" mountpoint="/"
fstype="ext4" instance="172.20.32.15" mountpoint="/"

我已经在Grafana的转换中尝试过一些操作,但没有找到符合我的需求的方法。我还花了一些时间尝试是否可以使用正则表达式,但这似乎过于复杂。

英文:

I have a Grafana view panel with a query that returns information for each node in a Kubernetes cluster. When the chart is displayed, the legend shows more information that needed. The query is as follows:

(1 - (node_filesystem_avail_bytes{fstype!="rootfs", mountpoint="/"} / node_filesystem_size_bytes{fstype!="rootfs", mountpoint="/"})) * 100

If I run this query in Prometheus, I get something like this (values are omitted):

{container="node-exporter", device="/dev/mapper/ubuntu--vg-ubuntu--lv", endpoint="http-metrics", fstype="ext4", instance="172.20.32.10:9100", job="node-exporter", mountpoint="/", namespace="prometheus", pod="prometheus-prometheus-node-exporter-xvz7v", service="prometheus-prometheus-node-exporter"}
{container="node-exporter", device="/dev/mapper/ubuntu--vg-ubuntu--lv", endpoint="http-metrics", fstype="ext4", instance="172.20.32.11:9100", job="node-exporter", mountpoint="/", namespace="prometheus", pod="prometheus-prometheus-node-exporter-w8cqq", service="prometheus-prometheus-node-exporter"}
{container="node-exporter", device="/dev/mapper/ubuntu--vg-ubuntu--lv", endpoint="http-metrics", fstype="ext4", instance="172.20.32.12:9100", job="node-exporter", mountpoint="/", namespace="prometheus", pod="prometheus-prometheus-node-exporter-4wfhq", service="prometheus-prometheus-node-exporter"}
{container="node-exporter", device="/dev/mapper/ubuntu--vg-ubuntu--lv", endpoint="http-metrics", fstype="ext4", instance="172.20.32.13:9100", job="node-exporter", mountpoint="/", namespace="prometheus", pod="prometheus-prometheus-node-exporter-zfskj", service="prometheus-prometheus-node-exporter"}
{container="node-exporter", device="/dev/mapper/ubuntu--vg-ubuntu--lv", endpoint="http-metrics", fstype="ext4", instance="172.20.32.15:9100", job="node-exporter", mountpoint="/", namespace="prometheus", pod="prometheus-prometheus-node-exporter-cllnv", service="prometheus-prometheus-node-exporter"}

This is also what is populating the chart legend, making it very long and more verbose than needed. Each item in the legend is the collection of all labels associated with the metric in the query.

I'd like to be able to pare this information down so that only the labels that people care about are shown in the legend. For example, for this chart, I'd want to show:

fstype="ext4" instance="172.20.32.10" mountpoint="/"
fstype="ext4" instance="172.20.32.11" mountpoint="/"
fstype="ext4" instance="172.20.32.12" mountpoint="/"
fstype="ext4" instance="172.20.32.13" mountpoint="/"
fstype="ext4" instance="172.20.32.15" mountpoint="/"

I've been poking around in Grafana transformations, but haven't found anything that does what I need. I also spent a little time trying to see if a regular expression could somehow be used, but this seems to be too complex.

答案1

得分: 1

您可以使用查询图例配置来配置查询结果中的图例文本。

它位于您想要配置的查询下:具有名称“选项”的可折叠菜单。

从那里,您可以选择三种图例变体之一:

  • 自动 - 显示唯一标签。如果系列具有多个标签,还会显示所有重叠的标签。
  • 详细 - 显示所有标签名称。
  • 自定义 - 使用模板选择要包括的标签。例如,{{hostname}}会被标签hostname的标签值替换。清除输入并单击其外部以选择另一种模式。

对于您在问题中描述的格式,您将需要使用值为自定义

fstype="{{fstype}}" instance="{{instance}}" mountpoint="{{mountpoint}}"
英文:

You can configure text used as legend for query result with query legend configuration.

It is located under query you want to configure: collapsible menu with name "Options".

From there you can select either of three variants of legend:

  • Auto - Displays unique labels. Also displays all overlapping labels if a series has multiple labels.
  • Verbose - Displays all label names.
  • Custom - Uses templating to select which labels will be included. For example, {{hostname}} is replaced by the label value for the label hostname. Clear the input and click outside of it to select another mode.

For format you described in your question you'll need Custom with value

fstype="{{fstype}}" instance="{{instance}}" mountpoint="{{mountpoint}}"

huangapple
  • 本文由 发表于 2023年6月8日 03:48:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76426673.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定