EC2 Discovery Relabelling

Let’s say you are on EC2 and wanted to use the Name tag rather than the private IP and port you’d get by default with EC2 service discovery. You could use a relabel rule like:

relabel_configs:
  - source_labels: [__meta_ec2_tag_Name]
    target_label: instance

You could go a step further and use the public rather than private IP, while also setting the instance label:

relabel_configs:
 - source_labels: [__meta_ec2_public_ip]
   regex:  '(.*)'             # This is the default value.
   target_label: __address__
   replacement: '${1}:9100'   # Have to specify a port too.
 - source_labels: [__meta_ec2_tag_Name]
   target_label: instance

See http://www.robustperception.io/controlling-the-instance-label/ for more information.

Rate this tip

If you think this tip by bbrazilbbrazil is useful — rate it up!

rating: +2+x
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License