Correctly using metric_relabel_configs

22 views
Skip to first unread message

Laurent Dumont

unread,
Nov 19, 2020, 5:32:19 PM11/19/20
to Prometheus Users
Hi!

I was trying to use metric_relabel_configs in order to change the label content (sourcing from another label) of a metric.

The original metric looks like this: 

collectd_openstack_nova_gauge{exported_instance="site1-director.potato.com",instance="123.123.123.123:9103",job="collectors",openstack_nova="hypervisor-site1-compute001.potato.com",role="Director",short_hostname="director",site="site1",tripleo_role="Director",type="hypervisor_version"}

In our case, because we are scraping a central endpoint, our short_hostname will carry the label of the actual scraped target. Ideally, I would want short_hostname to be changed to qasite1-compute001.

I've tried using the following metric_relabel_configs, but while it doesn't break anything, it doesn't seem to change the labels when looking at Prometheus.

    metric_relabel_configs:
      # Change the nova metric short_hostname to the compute name.
      - source_labels: ["openstack_nova"]
        regex: '([a-z]+.-compute\d\d\d)'
        target_label: "short_hostname"
        action: replace
        replacement: "$1"

This is placed within the job block that contains that scrape job.

Anything else I would need to double-check here? The Regex seems ok according to RE2 parsers, the syntax seems correct as well.

Thanks!

Christian Hoffmann

unread,
Nov 19, 2020, 5:55:38 PM11/19/20
to Laurent Dumont, Prometheus Users
Hi,

On 11/19/20 11:32 PM, Laurent Dumont wrote:
> collectd_openstack_nova_gauge{exported_instance="site1-director.potato.com
> <http://site1-director.potato.com>",instance="123.123.123.123:9103
> <http://123.123.123.123:9103>",job="collectors",openstack_nova="hypervisor-site1-compute001.potato.com
> <http://hypervisor-site1-compute001.potato.com>",role="Director",short_hostname="director",site="site1",tripleo_role="Director",type="hypervisor_version"}
>
> In our case, because we are scraping a central endpoint, our
> short_hostname will carry the label of the actual scraped target.
> Ideally, I would want short_hostname to be changed to qasite1-compute001.
>
> I've tried using the following metric_relabel_configs, but while it
> doesn't break anything, it doesn't seem to change the labels when
> looking at Prometheus.
>
>     metric_relabel_configs:
>       # Change the nova metric short_hostname to the compute name.
>       - source_labels: ["openstack_nova"]
>         regex: '([a-z]+.-compute\d\d\d)'

Prometheus regexps are fully anchored. Either try adding the
\.potato\.com suffix to the end of your regex (after the bracket) or
adapt the regex to add some wildcard (e.g. \..+) in the same place.

Kind regards,
Christian

Laurent Dumont

unread,
Nov 19, 2020, 9:26:20 PM11/19/20
to Christian Hoffmann, Prometheus Users
Thanks!

I missed that part. I'll tinker around with it.
Reply all
Reply to author
Forward
0 new messages