zoukankan      html  css  js  c++  java
  • 6. 配置项:relabel_config

    • 6.1relabel_config的位置
    • 6.2 relabel_config参数详解
      • 1.replace 
      • 2. keep
      • 3.drop
      • 6.labelkeep
      • 7.hashmod
    • 6.3 正则表达式

    重新标记是一种强大的工具,可以在抓取目标之前动态重写目标的标签集。 每个抓取配置可以配置多个重新标记步骤。 按照它们在配置文件中的出现顺序应用于每个目标的标签集。

    6.1relabel_config的位置

    1 global:
    2 ....
    3 # 抓取配置列表.
    4 scrape_configs:
    5   [ - <scrape_config> ... ]....
     1 # The job name assigned to scraped metrics by default.
     2 job_name: <job_name>
     3 
     4 [ honor_labels: <boolean> | default = false ]
     5 
     6 [ honor_timestamps: <boolean> | default = true ]
     7 
     8 # List of target relabel configurations.
     9 relabel_configs:
    10   [ - <relabel_config> ... ]
    11 
    12 # List of metric relabel configurations.
    13 metric_relabel_configs:
    14   [ - <relabel_config> ... ]
    15 ......

    6.2 relabel_config参数详解

     1 # 源标签从现有标签中选择值。 它们的内容使用已配置的分隔符进行连接,并与已配置的正则表达式进行匹配,以进行替换,保留和删除操作。
     2 [ source_labels: '[' <labelname> [, ...] ']' ]
     3 
     4 # 分隔符放置在连接的源标签值之间。
     5 [ separator: <string> | default = ; ]
     6 
     7 # 在替换操作中将结果值写入的标签。
     8 # 替换操作是强制性的。 正则表达式捕获组可用。
     9 [ target_label: <labelname> ]
    10 
    11 # 与提取的值匹配的正则表达式。
    12 [ regex: <regex> | default = (.*) ]
    13 
    14 # 采用源标签值的散列的模数。
    15 [ modulus: <uint64> ]
    16 
    17 # 如果正则表达式匹配,则执行正则表达式替换的替换值。 正则表达式捕获组可用。
    18 [ replacement: <string> | default = $1 ]
    19 
    20 # 基于正则表达式匹配执行的操作。
    21 [ action: <relabel_action> | default = replace ]

    <regex>是任何有效的RE2正则表达式。 它是replacekeepdroplabelmaplabeldroplabelkeep操作所必需的。 正则表达式固定在两端。 要取消锚定正则表达式,请使用。* <regex>.*

    <relabel_action>确定要采取的重新签名行动:

    1.replace 

    regex与连接的source_labels匹配。 然后,将target_label设置为replacement,将匹配组引用(${1}${2},...)替换为其值。 如果正则表达式不匹配,则不进行替换。

     1 scrape_configs:
     2  - job_name: file
     3      file_sd_configs:
     4      - files:
     5          - '*.json'
     6 #例如:team="monitoring"-->team_new="monitor"
     7      relabel_configs:
     8          -source_labels: [team]
     9              regex: monitoring
    10              replacement: monitor
    11              target_label: team_new
    12              action: replace
    13 #action的默认值是replace
    14        - source_labels: [__meta_consul_address]
    15              regex: '(.*)'
    16              replacement: '${1}:9100'
    17             target_label: __address__
    18 #参看上面看看这个什么意思
    19         - source_labels: [__meta_consul_tag]
    20              regex: '.*,(prod|staging|dev),.*'
    21              target_label: env

    2. keep

    删除regex与连接的source_labels不匹配的目标。

    1 scrape_configs:
    2     - job_name: node
    3            consul_sd_configs:
    4         - server: 'localhost:8500'
    5          relabel_configs:
    6              - source_labels: [__meta_consul_tag]
    7              regex: '.*,prod,.*'
    8              action: keep

    3.drop

    删除regex与连接的source_labels匹配的目标。

    1 scrape_configs: 
    2     - job_name: node 
    3     consul_sd_configs: 
    4     - server: 'localhost:8500' 
    5     relabel_configs: 
    6         - source_labels: [__meta_consul_tag] 
    7         regex: '.*,prod,.*' 
    8         action: drop


    4.labelmap

     将regex与所有标签名称匹配。 然后将匹配标签的名称替换为replacement指定的值。(不同于replace,keep,drop,只改变label名,不修改标签值)

     1 scrape_configs:
     2  - job_name: ec2
     3  ec2_sd_configs:
     4  - region: <region>
     5  access_key: <access key>
     6  secret_key: <secret key>
     7 #将所有以monitor_开头的标签名替换为去掉monitor_前缀的新标签名字(例如:monitor_foo="bar"-->foo="bar")
     8  relabel_configs:
     9  - regex: monitor_(.*)
    10  replacement: '${1}'
    11  action: labelmap

    5.labeldrop

    regex与所有标签名称匹配。匹配的任何标签都将从标签集中删除。(理labelmap)5.labeldrop

    6.labelkeep

    regex与所有标签名称匹配。任何不匹配的标签都将从标签集中删除。(同理labelmap)

    7.hashmod

    target_label设置为连接的source_labels的哈希模数。

     1 scrape_configs:
     2     - job_name: my_job
     3  # Service discovery etc. goes here.
     4         relabel_configs:
     5 #prometheus从特定targets随机抓取数据量的10%
     6          - source_labels: [__address__]
     7              modulus: 10
     8              target_label: __tmp_hash
     9              action: hashmod
    10          - source_labels: [__tmp_hash]
    11              regex: 0   #指定抓取的目标
    12              action: keep

    必须小心使用labeldroplabelkeep,以确保在删除标签后仍然对指标进行唯一标记。

    6.3 正则表达式

  • 相关阅读:
    Sum Root to Leaf Numbers
    Sum Root to Leaf Numbers
    Sort Colors
    Partition List
    Binary Tree Inorder Traversal
    Binary Tree Postorder Traversal
    Remove Duplicates from Sorted List II
    Remove Duplicates from Sorted List
    Search a 2D Matrix
    leetcode221
  • 原文地址:https://www.cnblogs.com/chenmingming0225/p/13080851.html
Copyright © 2011-2022 走看看