如何在Prometheus中的度量标准内重命名标签 [英] How to rename label within a metric in Prometheus

查看:675
本文介绍了如何在Prometheus中的度量标准内重命名标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个查询:

node_systemd_unit_state{instance="server-01",job="node-exporters",name="kubelet.service",state="active"} 1

我只希望在node_systemd_unit_state度量标准内将标签name重命名(或替换)为unit_name.因此,理想的结果是:

I want the label name being renamed (or replaced) to unit_name ONLY within the node_systemd_unit_state metric. So, desired result is:

node_systemd_unit_state{instance="server-01",job="node-exporters",unit_name="kubelet.service",state="active"} 1

node-exporters作业中还有许多其他标签名称为name的指标.这就是为什么我不能在整个工作中使用relabel config的原因.

There are many other metrics with a label name name in the node-exporters job. That's why I can't use relabel config across the job.

推荐答案

您可以有多个源标签,因此:

You can have more than one source label, so:

- source_labels: [__name__, name]
  regex: "node_systemd_unit_state;(.+)"
  target_label: unit_name

如果标签名称与其他指标/出口商不匹配,则应向其提交错误.像这样重新标记只能是在寻求适当解决方案时的一个临时解决方案.

If the label name isn't matching up with other metrics/exporters, you should file a bug with them. Relabelling like this should only be a temporary solution while a proper fix is being pursued.

这篇关于如何在Prometheus中的度量标准内重命名标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆