promethus 的 relabel_configs 和 metric_relabel_configs

很多童鞋在群里面反馈 relabel_configs 和 metric_relabel_configs 两个配置使用区别。都是relabel

譬如relabel_configs的relabel如下:

  - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
    separator: ;
    regex: "true"
    replacement: $1
    action: keep
  - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
    separator: ;
    regex: ([^:]+)(?::\d+)?;(\d+)
    target_label: __address__
    replacement: $1:$2
    action: replace
  - separator: ;
    regex: (.*)
    target_label: cluster
    replacement: test
    action: replace

metric_relabel_configs的relabel如下:

  metric_relabel_configs:
  - source_labels: [image]
    regex: '.*/(.*)'
    replacement: '$1'
    target_label: id
  - source_labels: [service]
    regex: 'ecs-.*:ecs-([a-z]+-*[a-z]*).*:[0-9]+'
    replacement: '$1'
    target_label: service

看着很相似,但relabel_configs是针对target指标采集前和采集中的筛选,而metric_relabel_configs是针对指标采集后的筛选。

譬如relabel_configs drop动作,

  relabel_configs:
      - source_labels: [__meta_ec2_tag_Name]
        regex: Example.*
        action: drop

那么将不会收集这个指标。而metric_relabel_configs使用的时候指标已经采集过了

  metric_relabel_configs:
  - source_labels: [__name__]
    regex: '(container_tasks_state|container_memory_failures_total)'
    action: drop

所以metric_relabel_configs相对来说,更加昂贵,毕竟指标已经采集了。

metric_relabel_configs还可以不用指定source_labels

  metric_relabel_configs:
  - regex: 'container_label_com_amazonaws_ecs_task_arn'
    action: labeldrop

你可能感兴趣的:(prometheus,监控,prometheus)