Prometheus relabel regex

1,020 views
Skip to first unread message

dzh...@contextlogic.com

unread,
Jul 10, 2017, 4:25:33 PM7/10/17
to Prometheus Users
Hello all,

I was just wondering how I can exclude some metrics while relabelling metrics and performing hashmod on them. For example. I have a lot of histogram-related metrics which I do not want to relabel/add new label to, so I'm looking for a way to match all metrics **without** the strings "sum", "bucket", or "count" in their names. How can I do that?

Thanks.

Ben Kochie

unread,
Jul 10, 2017, 4:58:12 PM7/10/17
to dzh...@contextlogic.com, Prometheus Users
Unfortunately, I think what you want is a "negative lookahead".  This is not supported by the re2 library Prometheus uses.

--
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-users+unsubscribe@googlegroups.com.
To post to this group, send email to prometheus-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/36b88b1d-b82c-436e-82b0-8c77d396d696%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

dzh...@contextlogic.com

unread,
Jul 10, 2017, 5:07:37 PM7/10/17
to Prometheus Users, dzh...@contextlogic.com
Hello Ben,

Thank you very much for your reply. Do you think the following will work?

metric_relabel_configs:
    - source_labels: ["__name__"]
      modulus: 25
      target_label: "__tmp_hash"
      action: "hashmod"
    # drop __tmp_hash label for histogram-related metrics
    - source_labels: ["__name__"]
      regex: ".*(sum|count|bucket)"
      target_label: "__tmp_hash"
      action: labeldrop

Thanks,
DZ


On Monday, July 10, 2017 at 1:58:12 PM UTC-7, Ben Kochie wrote:
Unfortunately, I think what you want is a "negative lookahead".  This is not supported by the re2 library Prometheus uses.
On Mon, Jul 10, 2017 at 10:25 PM, dzhang via Prometheus Users <promethe...@googlegroups.com> wrote:
Hello all,

I was just wondering how I can exclude some metrics while relabelling metrics and performing hashmod on them. For example. I have a lot of histogram-related metrics which I do not want to relabel/add new label to, so I'm looking for a way to match all metrics **without** the strings "sum", "bucket", or "count" in their names. How can I do that?

Thanks.

--
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 post to this group, send email to promethe...@googlegroups.com.

Brian Brazil

unread,
Jul 10, 2017, 5:09:44 PM7/10/17
to dzh...@contextlogic.com, Prometheus Users
On 10 July 2017 at 22:07, dzhang via Prometheus Users <promethe...@googlegroups.com> wrote:
Hello Ben,

Thank you very much for your reply. Do you think the following will work?

metric_relabel_configs:
    - source_labels: ["__name__"]
      modulus: 25
      target_label: "__tmp_hash"
      action: "hashmod"
    # drop __tmp_hash label for histogram-related metrics
    - source_labels: ["__name__"]
      regex: ".*(sum|count|bucket)"
      target_label: "__tmp_hash"
      action: labeldrop

You need a normal replace action rather than a labeldrop. The replacement for that should be the empty string, so that the label is removed.

Brian

 
Thanks,
DZ

On Monday, July 10, 2017 at 1:58:12 PM UTC-7, Ben Kochie wrote:
Unfortunately, I think what you want is a "negative lookahead".  This is not supported by the re2 library Prometheus uses.

On Mon, Jul 10, 2017 at 10:25 PM, dzhang via Prometheus Users <promethe...@googlegroups.com> wrote:
Hello all,

I was just wondering how I can exclude some metrics while relabelling metrics and performing hashmod on them. For example. I have a lot of histogram-related metrics which I do not want to relabel/add new label to, so I'm looking for a way to match all metrics **without** the strings "sum", "bucket", or "count" in their names. How can I do that?

Thanks.

--
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 post to this group, send email to promethe...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/36b88b1d-b82c-436e-82b0-8c77d396d696%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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-users+unsubscribe@googlegroups.com.
To post to this group, send email to prometheus-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/112441a3-399e-4e61-b836-c549a7b720be%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

dzh...@contextlogic.com

unread,
Jul 10, 2017, 5:16:10 PM7/10/17
to Prometheus Users, dzh...@contextlogic.com
Thank you Brian. It worked.



--
Reply all
Reply to author
Forward
0 new messages