假设我有一个名为metrics-app-123456-spark-whatever-1
的度量。
我知道您可以使用以下选项来重新标记:
- https://prometheus.io/docs/prometheus/latest/configuration/configuration/relabel_config
- https://prometheus.io/docs/prometheus/latest/configuration/configuration/metric_relabel_configs
使用这两个,我可以重命名度量名称或标签,但在这种情况下,我如何使用来自度量名称的应用程序ID作为标签添加? 基本上,我没有看到使用来自度量名称的正则表达式来重命名标签的方法。
。metrics-app-123456-spark-whatever-1
→metrics-spark-whatever-1{app=123456}
试试下面的PromQL:
label_replace(label_replace(metrics-app-123456-spark-whatever-1{}, "app", "$3", "__name__", "(.*)-(.*)-(.*)-(.*)-(.*)-(.*)"), "__name__", "$1-$4-$5-$6", "__name__", "(.*)-(.*)-(.*)-(.*)-(.*)-(.*)")
Q:我如何使用应用程序ID从度量名称添加为标签?
A:使用prometheus函数:label_replace ()