regex 如何在prometheus中定义一个提供默认值的relabel_config?

olqngx59  于 2023-03-04  发布在  其他
关注(0)|答案(1)|浏览(339)

假设我有通常侦听端口8080的服务,如果我指定

prometheus.port=1234

它使用1234作为示例端口,但如果不指定它,我将得到8080作为我在标签上设置的值
我猜大概是因为

- source_labels: [__meta_dockerswarm_service_label_prometheus_port]
  regex: (\d+)
  target_label:  __port__
  replace: $1
  action: replace
czq61nw1

czq61nw11#

- target_label:  __port__
  replacement: 8080
  action: replace

- source_labels: [__meta_dockerswarm_service_label_prometheus_port]
  regex: (\d+)
  target_label:  __port__
  replacement: $1
  action: replace

然后与以下内容结合使用以提供服务的端口号

- source_labels: [ __meta_dockerswarm_service_name ]
  target_label: service
  action: replace
- source_labels: [ __address__ ]
  target_label: __address__
  regex: (.+):(\d+)
  replacement: $1
  action: replace
- source_labels: [ __address__, __port__ ]
  target_label: __address__
  regex: (.+);(\d+)
  replacement: $1:$2
  action: replace

相关问题