All Products
Search
Document Center

Cloud Monitor:Example scenarios for metric_relabel_configs

Last Updated:Dec 25, 2025

The official Prometheus documentation provides complete usage details for metric_relabel_configs. This topic provides examples of the following common scenarios:

  • Delete unwanted metrics

  • Add a specific label

  • Delete unwanted labels

Delete unwanted metrics

An example configuration is as follows:

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

An example configuration is as follows:

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

An example configuration is as follows:

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