我具有followinf形式的指标:
kube_deployment_labels{deployment="application1-deployment",endpoint="http",instance="10.273.78.36:8180",job="kube-state-metrics",label_app="applcation-request-adapter",label_environment="dev",label_version="dev",namespace="default",pod="kore-prom-kube-state-metrics-654d86c799-2kqzs",service="kore-prom-kube-state-metrics"}
我需要在名称空间上对dev_namespace进行标签替换,对label_version对dev_version进行标签替换。如何编写嵌套的label_replace语句?我可以将它们分别应用于:
label_replace(kube_deployment_labels{label_app=~".*",label_environment=~"dev",label_version=~"dev"}, "dev_namespace", "$1", "namespace", "(.*)")
和
label_replace(kube_deployment_labels{label_app=~".*",label_environment=~"dev",label_version=~"dev"}, "dev_version", "$1", "label_version", "(.*)")
如何将它们组合在一起以在Prometheus中同时重命名或替换多个标签?
经过一些解决,我找到了解决方案。我以为我会在这里张贴它,以便其他人可以看看:
label_replace(label_replace(kube_deployment_labels{label_app=~".*",label_environment=~"dev",label_version=~"dev"}, "dev_namespace", "$1", "namespace", "(.*)"), "dev_version", "$1", "label_version", "(.*)")