【问题标题】:Prometheus/ create list of tag from __meta_gce_tagsPrometheus/ 从 __meta_gce_tags 创建标签列表
【发布时间】:2018-04-11 06:02:31
【问题描述】:

我使用relabeling 将 gce 标签带到 Prometheus 标签,通过在 Prometheus yml 中使用以下代码:

 relabel_configs:
  - source_labels: [__meta_gce_tags]
    target_label: tags

标签如下所示:

tags=",node_a,node_prod,node_centos,"

问题是它给出了一个字符串列表,而我希望有标签列表以便我可以查询它。例如,而不是使用:

sum(elasticsearch_node_stats_up{tags=~".*?noda_a.*node_prod.?"})

我将能够在没有正则表达式的情况下使用它。有什么办法吗?

【问题讨论】:

    标签: regex prometheus


    【解决方案1】:

    您可以在重新标记期间使用正则表达式从标签值中提取值。所以试试这个,它不完全是 DRY,但有效:

    relabel_configs:
      - source_labels: [__meta_gce_tags]
        regex: ",node_([a-z]+),node_[a-z]+,node_[a-z]+"
        target_label: node
        replacement: '${1}'
      - source_labels: [__meta_gce_tags]
        regex: ",node_[a-z]+,node_([a-z]+),node_[a-z]+"
        target_label: env
        replacement: '${1}'
      - source_labels: [__meta_gce_tags]
        regex: "",node_[a-z]+,node_[a-z]+,node_([a-z]+)""
        target_label: os
        replacement: '${1}'
    

    请注意,可能有一个更优雅的正则表达式可供使用。

    如果你可以控制标签值,这里有一个更持久的技术:https://www.robustperception.io/extracting-full-labels-from-consul-tags/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-07
      • 2020-03-17
      • 2020-01-02
      • 1970-01-01
      • 2019-12-21
      • 1970-01-01
      • 2019-01-24
      相关资源
      最近更新 更多