例如,我有不同标签的teo指标
node_metrics_first{foo="bar",AAA="aaa"}
node_metrics_second{BBB="bbb",CCC="ccc"}
如何在 servicemonitor 中使用 relabeling/metricRelabeling drop/labeldrop 来删除 node_metrics_first 中的 foo 标签,这意味着我应该得到结果:
node_metrics_first{AAA="aaa"}
node_metrics_second{BBB="bbb",CCC="ccc"}
Grafana 有一篇内容广泛的博客,介绍重新标记的工作原理。在你的情况下:
- job_name: some_job
metric_relabel_configs:
- regex: "foo"
action: labeldrop
在 Prometheus operator ServiceMonitors 中,您可以使用
spec.endpoints[*].relabelings
更改标签和指标:
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
spec:
endpoints:
- interval: 30s
port: metrics
scheme: http
relabelings: <-- here you shine!
- action: labeldrop
regex: (foo|otherlabeltodrop)