EN VI

Regex - Prometheus relabeling configureation incremental counter?

2024-03-12 18:00:06
How to Regex - 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.

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.

Answer

Login


Forgot Your Password?

Create Account


Lost your password? Please enter your email address. You will receive a link to create a new password.

Reset Password

Back to login