【问题标题】:Prometheus relabeling not working as expectedPrometheus 重新标记未按预期工作
【发布时间】:2017-09-07 07:27:03
【问题描述】:

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

例如,当__address__ 已设置为myhost.mydomain.com:8080hostname 应设置为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:   ${1}
      target_label:  'hostname'

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

【问题讨论】:

    标签: monitoring prometheus


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-07
      • 2022-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-03
      • 2018-06-06
      • 2019-04-18
      相关资源
      最近更新 更多