Prometheus 重新标记未按预期工作

Prometheus relabeling not working as expected

我想使用 Prometheus 的 relabeling 添加标签 hostname,它应该是 targets 提供的更简洁的 instance 版本。这应该允许在 Grafana 仪表板中使用更紧凑的图例。

例如,当__address__设置为myhost.mydomain.com:8080时,hostname应设置为myhost。我使用 __address__ 而不是 instance 作为 source_label,因为第二个 apparently 在重新标记时尚未设置。

我的 prometheus.yaml 的相关摘录如下(意在使用 lazy 正则表达式):

- job_name: 'node_exporter'

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

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

预期的新标签 hostname 尚未添加。我的设置可能有什么问题?

有了这个正则表达式(带有 non-capturing group),事情就开始起作用了:'(.+?)(?:[\.:].+)?'.