Dropping metrics with specific lables

62 views
Skip to first unread message

Hossman12

unread,
Sep 7, 2023, 9:03:41 AM9/7/23
to Prometheus Users
I'm using file_sd_configs  and I need to drop/filter out a metric that has a specific label.

I have tried this but it drops all the metrics

scrape_configs:
  - job_name: 'dummy'  # This is a default value, it is mandatory.
    file_sd_configs:
      - files:
        - /opt/prometheus/targets/*.core.json
        refresh_interval: 5m
    metric_relabel_configs:
      - source_labels: [ __name__]
        regex: 'node_systemd_unit_state'
        action: drop

But I want to just drop metrics for node_systemd_unit_state that have the label 'name' match some specific patterns.   name=~"*(pattern1|pattern2)*"

I know I could modify the node_exporter config to drop specific services but I don't have the ability to do that to all endpoints so I'd like to drop them at the scrape level. 

Brian Candler

unread,
Sep 7, 2023, 9:37:40 AM9/7/23
to Prometheus Users
> But I want to just drop metrics for node_systemd_unit_state that have the label 'name' match some specific patterns.   name=~"*(pattern1|pattern2)*"

   metric_relabel_configs:
      - source_labels: [ __name__, name]
        regex: 'node_systemd_unit_state;.*(pattern1|pattern2).*'
        action: drop

Giving multiple source_labels concatenates the given labels, using a semicolon separator by default, and then the regex matches against the whole result.

(Aside: job name is mandatory, but it gets added to the metrics as the 'job' label, so it's worth giving it a meaningful name rather than "dummy")
Reply all
Reply to author
Forward
0 new messages