Prometheus - Relabel

通过对标签的重命名进行重整操作,便于统一化管理或者服务升级前后管理。


原始数据:

cat targets/node-exporter.yml

- targets:
  - "172.20.31.195:9100"
  labels:
    __os__: "linux"
    __release__: "redhat"
- targets:
  - "172.20.31.196:9100"
  labels:
    __os__: "linux"
    __release__: "centos"
- targets:
  - "172.20.31.197:9100"
  labels:
    __os__: "linux"
    __release__: "centos"

Prometheus - Relabel




replace: 对原有的标签进行更名

scrape_configs:
  - job_name: 'node-exporter'
    file_sd_configs:
    - files:
      - targets/node-exporter.yml
      refresh_interval: 1m
    relabel_configs:
    - source_labels:
      - "__os__"
      regex: "(.*)"
      target_label: "os"
      action: replace
      replacement: "$1"


Prometheus - Relabel



replace-separator: 对字段进行合并处理

scrape_configs:
  - job_name: 'node-exporter'
    file_sd_configs:
    - files:
      - targets/node-exporter.yml
      refresh_interval: 1m
    relabel_configs:
    - source_labels:
      - "__os__"
      - "__release__"
      separator: "-"
      regex: "(.*)"
      target_label: "os_release"
      action: replace
      replacement: "$1"


Prometheus - Relabel



keep: 满足特定条件的实例进行采集,其他的不采集。

scrape_configs:
  - job_name: 'node-exporter'
    file_sd_configs:
    - files:
      - targets/node-exporter.yml
      refresh_interval: 1m
    relabel_configs:
    - source_labels:
      - "__release__"
      regex: "redhat"
      action: keep


Prometheus - Relabel



drop: 满足特定条件的实例不采集,其他的采集。

scrape_configs:
  - job_name: 'node-exporter'
    file_sd_configs:
    - files:
      - targets/node-exporter.yml
      refresh_interval: 1m
    relabel_configs:
    - source_labels:
      - "__release__"
      regex: "redhat"
      action: drop


Prometheus - Relabel




labelkeep: 对抓取的实例特定标签进行保留,其他标签删除。

scrape_configs:
  - job_name: 'node-exporter'
    file_sd_configs:
    - files:
      - targets/node-exporter.yml
      refresh_interval: 1m
    relabel_configs: 
    - source_labels:
      - "__os__"
      regex: "(.*)"
      target_label: "os"
      action: replace
      replacement: "$1"
    - source_labels:
      - "__release__"
      regex: "(.*)"
      target_label: "release"
      action: replace
      replacement: "$1"
    - regex: "jobs"
      action: labelkeep


labeldrop: 对抓取的实例特定标签进行删除。

scrape_configs:
  - job_name: 'node-exporter'
    file_sd_configs:
    - files:
      - targets/node-exporter.yml
      refresh_interval: 1m
    relabel_configs: 
    - source_labels:
      - "__os__"
      regex: "(.*)"
      target_label: "os"
      action: replace
      replacement: "$1"
    - source_labels:
      - "__release__"
      regex: "(.*)"
      target_label: "release"
      action: replace
      replacement: "$1"
    - regex: "os"
      action: labeldrop


Prometheus - Relabel



hashmod:将target_label设置成source_label的modulus配置的hash值;



labelmap:将regex匹配到的所有标签的名称配置成新的标签,值配置成新标签的值;



上一篇:Istio - crds - Vistrual Service


下一篇:YOLOV5训练自己数据集