0

我正在尝试从 prometheus 配置中的 cadvisor 重命名相同的标签。cadvisor 名称太长了,所以我有以下配置用于重新标记。

  - job_name: 'cadvisor job foo'
scrape_interval: 60s
ec2_sd_configs:
  - role_arn: 'arn:aws:iam::$id:role/foo'
    region: 'us-west-2'
    port: 8484
relabel_configs:
  - source_labels: [__meta_container_label_com_amazonaws_ecs_cluster]
    target_label: cluster_name
  - source_labels: [__meta_container_label_com_amazonaws_ecs_container_name]
    target_label: container_name  

不幸的是,这似乎不起作用。这甚至可以在普罗米修斯配置中重新标记 cadvisor 标签吗?

4

1 回答 1

0

你确定标签__meta_container_label_com_amazonaws_ecs_cluster存在吗?我在 AWS ECS 集群中运行 Cadvisor,并从 container_label_com_amazonaws_ecs_container_name. 它不是元标签,而是由 Cadvisor 从 Docker 标签中提取的。

__meta.+标签由 检索relabel_configs。这是我配置的那部分的样子:


  - job_name: cadvisor
    ec2_sd_configs:
      - region: eu-central-1
        port: 28080
        filters:
          - name: tag:aws:autoscaling:groupName 
            values:
              - data-dev
              - data-prod

    relabel_configs:
      - action: replace
        source_labels: [__meta_ec2_instance_id]
        target_label: instance_id
      - action: replace
        source_labels: [__meta_ec2_instance_state]
        target_label: instance_state
      - action: replace
        source_labels: [__meta_ec2_instance_type]
        target_label: instance_type

    metric_relabel_configs:

      # Drop series.
      - action: drop
        source_labels: [__name__]
        regex: "(container_tasks_state|container_cpu_load_average_10s)"
      
      # Drop all series that do not have a 'name' label.
      - action: keep
        source_labels: [name]
        regex: (.+)

      # Drop all series that do not have a '/ecs/' c group prefix and a proper 
      # container id after the third forword slash.
      - action: keep
        source_labels: [id]
        regex: ^/ecs/.+/.+

      # Drop label 'instance_type'.
      - action: labeldrop
        regex: instance_type

      # Rewrite 'id' label to only include short form container id.
      - action: replace
        source_labels: [id]
        target_label: id
        regex: ^/ecs/.+/(.{0,12}).*
        replacement: $1

      # Rename label task family.
      - action: replace
        source_labels: [container_label_com_amazonaws_ecs_task_definition_family]
        target_label: task_family
      - action: labeldrop
        regex: container_label_com_amazonaws_ecs_task_definition_family

      # Overwrite 'name' with value of container name label.
      - action: replace
        source_labels: [container_label_com_amazonaws_ecs_container_name]
        target_label: name
      - action: labeldrop
        regex: container_label_com_amazonaws_ecs_container_name

      # namespace
      - action: replace
        source_labels: [container_label_promstack_namespace]
        target_label: namespace
      - action: labeldrop
        regex: container_label_promstack_namespace

      # api_type
      - action: replace
        source_labels: [container_label_promstack_api_type]
        target_label: api_type
      - action: labeldrop
        regex: container_label_promstack_api_type
于 2020-10-09T10:06:51.457 回答