您可以在抓取后使用metric_relabel_configs重写标签。一个例子:
- job_name: pushgateway
# This is necessary if metrics in pushgateway have "job" or "instance" labels.
# With "honor_labels: true" Prometheus will save those as "exported_job" and "exported_instance" respectively.
honor_labels: true
static_configs:
- targets:
- my-pushgateway.com:9091
metric_relabel_configs:
# copy pushgateway address from "instance" to "source" label
- source_labels: [instance]
target_label: source
# replace "instance" label value with one from "exported_instance" label
- source_labels: [exported_instance]
target_label: instance
# remove "exported_instance" label
- source_labels: [exported_instance]
action: labeldrop
如果您以前有这样的指标:
my_metric{job="pushgateway", instance="my-pushgateway.com:9091", exported_instance="example.com"}
然后使用上面示例中的配置,它们将如下所示:
my_metric{job="pushgateway", instance="example.com", source="my-pushgateway.com:9091"}