I have a scrape job with lots of ec2_scrape_configs sections, which scrapes multiple accounts and regions.
Getting the account ID is easy (it's in __meta_ec2_owner_id). What I'm trying to find is, is there a clean and direct way to obtain the region? The best I could come up with was a frig to match the instance's private DNS name, which seems to include the region except when in us-east-1:
relabel_configs:
- source_labels: [__meta_ec2_private_dns_name]
regex: '.*[.]ec2[.]internal'
replacement: us-east-1
target_label: region
- source_labels: [__meta_ec2_private_dns_name]
regex: '.*[.]([^.]+)[.]compute[.]internal'
target_label: region
This feels wrong. I'd be fine specifying it explicitly, like this:
ec2_sd_configs:
- access_key: AKIA.....
secret_key: XXXX.....
region: eu-west-1
refresh_interval: 1h
labels:
region: eu-west-1
- access_key: AKIA.....
secret_key: XXXX.....
region: eu-west-2
refresh_interval: 1h
labels:
region: eu-west-2
... etc
However, that doesn't work, because only static_sd_configs and file_sd_configs permit labels to be specified for groups of targets like this.
The job has a rather long and complicated set of relabelling rules, so I'd rather not have to duplicate the logic across a separate scrape job per region.
Have I missed something?
Thanks,
Brian.