0

I would like to employ Prometheus' relabeling for adding a label hostname, which should be a more concise version of instance as provided by targets. This should allow more compact legends in Grafana dashboards.

For instance, when __address__ has been set to myhost.mydomain.com:8080, hostname should be set to myhost. I am using __address__ rather than instance as source_label, because the second is apparently not yet set when relabeling occurs.

The relevant excerpt of my prometheus.yaml looks as follows (it is meant to employ a lazy regular expression):

- job_name: 'node_exporter'

  static_configs:
    - targets: ['myhost1.mydomain.com:8080',
                'myhost2.mydomain.com:8080']

  relabel_configs:
    - source_labels: ['__address__']
      regex:         '^([^\.:]+?)'
      replacement:   ${1}
      target_label:  'hostname'

The expected new label hostname is not yet added. What could be wrong in my setup?

rookie09
  • 736
  • 1
  • 6
  • 18

1 Answers1

0

With this regex (with a non-capturing group) things have come to work: '(.+?)(?:[\\.:].+)?'.

rookie09
  • 736
  • 1
  • 6
  • 18