Example scenarios for metric_relabel_configs

更新时间:
复制 MD 格式

For complete usage details, see the official Prometheus documentation. The following examples cover common metric_relabel_configs scenarios:

  • Delete unwanted metrics

  • Add a specific label

  • Delete unwanted labels

Delete unwanted metrics

Example configuration:

scrape_configs:
  - job_name: "customJob_name1"
    ...
    relabel_configs:
    ...
    metric_relabel_configs: 
    - source_labels: [__name__]
  		action: drop
  		regex: 'pre1_.*' # Deletes all metrics with the "pre1_" prefix that are scraped by customJob_name1.
    - source_labels: [__name__]
  		action: drop
  		regex: 'metric_name1' # Deletes the metric named "metric_name1" that is scraped by customJob_name1.		  		

Add a specific label

Example configuration:

scrape_configs:
  - job_name: "customJob_name1"
    ...
    relabel_configs:
    ...
    metric_relabel_configs: 
    # Adds the label "new_label1" with the value "label_value1" to all metrics scraped by customJob_name1.
    - regex: (.*)
      target_label: new_label1
      replacement: label_value1
      separator: ;
      action: replace	  		

Delete unwanted labels

Example configuration:

scrape_configs:
  - job_name: "customJob_name1"
    ...
    relabel_configs:
    ...
    metric_relabel_configs: 
    - regex: 'pre1_.*'  # Deletes all labels with the "pre1_" prefix from all metrics scraped by customJob_name1.
      action: labeldrop