Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Prometheus relabeling configureation incremental counter

I’m trying to scrape metrics from my ec2 machines.
Those machines has a complex name due to Auto scaling group.
For example:

  • ProjectName/project-name-dev-cluster/project-name-dev-LaunchTemplate
  • ProjectName/project-name-prod-cluster/project-name-prod-LaunchTemplate
  • ProjectName/project-name-prod-cluster/project-name-prod-LaunchTemplate

Beyond their name, I need to relabel the names in the relabel_configs section in the prometheus.yaml: I need to rename those machines to look something like this: project_name-environment-counter so, for example:

  • project_name-dev-1
  • project_name-prod-1
  • project_name-prod-2

so basically I need to count how many dev and prod machines are.
I’ve tried something but noting worked.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Any suggestions?

>Solution :

You can’t do this: unless counter you want to use is already a part of machine’s name (or any other label) you cannot achieve described goal.

Prometheus’ relabel_config can only use labels of the target (metric_relabel_configs can also use labels of the time series itself, but it doesn’t help here). And those labels are limited to the target of relabeling. So no way of knowing what how many other machines with similar names are present, nor iterating with some kind of variable.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading