【问题标题】:Adding metric labels in prometheus on the fly在 prometheus 中动态添加指标标签
【发布时间】:2019-06-23 09:06:54
【问题描述】:

我在 prometheus 中有一个计数器指标。我想动态添加标签,例如如果我的请求来自 http://abc123.com/{p1} ,我希望我的 custom_metric_name 存储 {statuscode=200, p1=p1Value , host="abc123"} 并且如果请求来自 http://def123.com/{p2} 。我希望 custom_metric_name 存储 {statuscode=200, p2=p2Value , host="def123"}custom_metric_name 将由两者共享指标。

我正在尝试仍然无法得到答案

【问题讨论】:

    标签: go label prometheus metrics dynamically-generated


    【解决方案1】:

    您可以在 Prometheus 配置中使用 relabel_configmetric_relabel_config

    如下所示:

    - source_labels: [request_origin]
      regex: 'http://(\w+)/.*'
      replacement: '${1}'
      target_label: host
    

    另见article 显示重新标记的用法。

    【讨论】:

    • 这不是添加而是更改标签,不是吗?
    • 这是因为target_label表示要创建新标签。
    猜你喜欢
    • 2021-08-25
    • 2021-12-16
    • 1970-01-01
    • 1970-01-01
    • 2019-08-28
    • 1970-01-01
    • 2018-09-24
    • 2019-08-09
    • 2020-11-09
    相关资源
    最近更新 更多