Drop label for single metric only, not for entire scrape job

1,390 views
Skip to first unread message

Peter Burrows

unread,
Feb 28, 2022, 7:48:49 AM2/28/22
to Prometheus Users
Hi folks, I have a scenario where I wish to drop label L from metric A. I easily found documentation on how to drop label L from all metrics within a job, however in my case I have another metric we'll call B that's in the same scrape job and for metric B label L is useful and shouldn't be dropped. I've been unable to find anything online to help with such a scenario. I basically want to drop a label for a specific metric but leave it in place for all other metrics in the same job. Is anyone aware of a way to achieve this, perhaps with metric_relabel_configs?

Julien Pivotto

unread,
Feb 28, 2022, 7:57:09 AM2/28/22
to Peter Burrows, Prometheus Users
On 25 Feb 03:47, 'Peter Burrows' via Prometheus Users wrote:
> Hi folks, I have a scenario where I wish to drop label *L* from metric *A*.
> I easily found documentation on how to drop label *L* from all metrics
> within a job, however in my case I have another metric we'll call *B*
> that's in the same scrape job and for metric *B* label *L* is useful and
> shouldn't be dropped. I've been unable to find anything online to help with
> such a scenario. I basically want to drop a label for a specific metric but
> leave it in place for all other metrics in the same job. Is anyone aware of
> a way to achieve this, perhaps with metric_relabel_configs?

You can do:

metric_relabel_configs:
- source_labels: [__name__,L]
target_label: L
replacement: ""
regex: 'A,.*'

Regards

>
> --
> You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/2b6620a2-36e8-48c5-ab87-2a1faf30fe83n%40googlegroups.com.


--
Julien Pivotto
@roidelapluie

Brian Candler

unread,
Mar 1, 2022, 2:39:52 AM3/1/22
to Prometheus Users
> regex: 'A,.*'

I think semicolon rather than comma?

Peter Burrows

unread,
Mar 1, 2022, 3:43:10 AM3/1/22
to Prometheus Users
metric_relabel_configs:
  - source_labels: [__name__,L]
    separator: ;
    action: replace
    regex: "A;.*"
    replacement: ""
    target_label: L

The above worked perfectly for me, thanks both for the help.

Reply all
Reply to author
Forward
0 new messages