概述
在 MetricQL 中,可以通过label_replace()
函数来修改标签名。
语法
1 | label_replace(vector, dst_label, replacement, src_label, regex) |
vector
:输入的时间序列数据。dst_label
:目标标签的名称,即新的标签名。replacement
:用于替换的字符串,可以包含正则表达式的捕获组。src_label
:源标签的名称,即当前需要被替换的旧标签名。regex
:用于匹配源标签值的正则表达式。
假设有一个时间序列数据http_requests_total
,其中有一个标签path
,现在想将其重命名为endpoint
,可以使用以下语法实现标签名修改:
1 | label_replace(http_requests_total, "endpoint", "$1", "path", "(.*)") |
这里(.*)
是一个正则表达式,它匹配path标签
的所有可能的值,并通过$1
将这个值赋给新的endpoint标签
。