简体   繁体   中英

Prometheus relabeling not working as expected

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM