關於metric_relabel_configs的完整使用,請參見Prometheus官方文檔。本文通過樣本,簡要介紹使用metric_relabel_configs的典型情境:
刪除不需要的指標
增加指定標籤
刪除不需要的標籤
刪除不需要的指標
典型配置樣本如下:
scrape_configs:
- job_name: "customJob_name1"
...
relabel_configs:
...
metric_relabel_configs:
- source_labels: [__name__]
action: drop
regex: 'pre1_.*' #刪除customJob_name1抓取的"pre1_"首碼的所有指標
- source_labels: [__name__]
action: drop
regex: 'metric_name1' #刪除customJob_name1抓取的"metric_name1"名稱的指標 增加指定標籤
典型配置樣本如下:
scrape_configs:
- job_name: "customJob_name1"
...
relabel_configs:
...
metric_relabel_configs:
#customJob_name1抓取的所有指標,增加“new_label1”標籤,標籤值為“lable_value1”
- regex: (.*)
target_label: new_label1
replacement: label_value1
separator: ;
action: replace 刪除不需要的標籤
典型配置樣本如下:
scrape_configs:
- job_name: "customJob_name1"
...
relabel_configs:
...
metric_relabel_configs:
- regex: 'pre1_.*' #customJob_name1抓取的所有指標,刪除“pre1_”首碼的所有標籤
action: labeldrop