1

I am trying to relabel after copying the existing metrics for Kafka only for below match

Kafka_log_size{partition=“1”, topic=“ab_bc_cd_12345_ef_001”,} 10

I want output as : Kafka_log_size{partition=“1”, topic=“ab_bc_cd_12345_ef_001”,} 10 Kafka_log_size_uniq{partition=“1”, uniq=“12345”,} 10

From reading multiple articles , it seems this can be achieved by relabeling . But not sure how to start with please advise . Thanks

4

1 回答 1

4

您有两个选项可以在 Prometheus 中重新标记您的指标:

在这两种情况下,您都需要有一个匹配topic标签内容并提取您需要的内容的正则表达式。

在配置中重新标记

在您为 Kafka 抓取的工作中,您必须匹配要替换的指标名称并使用重新标记配置

metric_relabel_configs:
  - source_labels: [topic] 
    regex: '[a-z_]+_([0-9]+)_.*'
    action: replace
    target_label: uniq
    replacement: $1

然后添加规则以删除标签

  - regex: 'topic'
    action: droplabel

在请求中重新标记

新标签是使用标签替换生成的:

label_replace(Kafka_log_size, "uniq", "$1", "topic", "[a-z_]+_([0-9]+)_.*")

然后,应用聚合运算符来删除不需要的标签:

max(label_replace(Kafka_log_size, "uniq", "$1", "topic", "[a-z_]+_([0-9]+)_.*")) without(topic)
于 2019-09-23T15:09:07.297 回答