Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using regular expressions in Prometheus relabel_configs source_labels

I'm trying to save the meta labels retrieved from EC2 Service Discovery as target labels. I'm mostly concerned about the tags - every instance contains a lot of them and I would love to gather them all using one simple configuration entry with the usage of regular expression.

The perfect solution seems to be something like this:

relabel_configs:
   - source_labels:
      - '__meta_ec2_tag_(.*)'
     target_label: '### use extracted regex group here'

Unfortunately, I get the following error:

\"__meta_ec2_tag_(.*)\" is not a valid label name"

Does that mean that I can't use regular expressions to describe source labels and that I have to specify each source label separately like in the sample below?

- source_labels:
    - '__meta_ec2_tag_Name'
  target_label: 'instance_name'

- source_labels:
    - '__meta_ec2_tag_environment'
  target_label: 'environment'

- source_labels:
    - '__meta_ec2_tag_project'
  target_label: 'project'
like image 453
mordowiciel Avatar asked Oct 15 '25 04:10

mordowiciel


1 Answers

Try this:

relabel_configs:
   - regex: '__meta_ec2_tag_(.*)'
    replacement: $1
like image 140
Alex Sveshnikov Avatar answered Oct 17 '25 20:10

Alex Sveshnikov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!