-2

I am trying to write a regex that will ignore the first two octets 'name.name-name.presto.worker' but will match the rest which is 'presto.worker'.

I have two different domain names that follow the same structure like I shown above and I need the monitoring system to catch both domains using the two last octects presto.worker.

My last regex that I have found that almost work is:

count(up{instance="/[A-Za-z.]+[A-Za-z.-]+(presto.)+(worker)/g"})

It's for Prometheuse monitoring system. Thanks for the help Yaniv

Yaniv Hakim
  • 77
  • 10

4 Answers4

1

I'm not sure what you mean by wanting to ignore the first two octets. If you're not interested in matching on them you could just use "presto\.worker" in your regex and that will match every instance.

If you want to also get the first two octets and filter them out, here is the regex for it:

([A-Za-z]+\.[A-Za-z]+-[A-Za-z]+\.)(presto\.worker)

The first two octets are now within a separeate group (Group 1). I'm not sure how the Prometheuse monitoring system will output theese matches though (usually you will get an array with every group). Try to paste the regex into regex101.com to see what I mean.

Hope this answers your question!

-Eivind

0

I have tried the two solutions and both has a different problem enter image description here

enter image description here Prometheus query issue:

Yaniv Hakim
  • 77
  • 10
0

On regex101.com I have put the filter that I am looking (to match by "presto.worker") and it does show a good match but when I run in on the Prometheus monitoring system it error with "unknown escape sequence"

I guess the forward slash need to escaped of so.How to do it ?

enter image description here

Yaniv Hakim
  • 77
  • 10
0

I have found the answer for that and thanks for directing me. for prometheus to treat a code as a regex we need to inset ~ at the beginning make the code like that:

count(up{instance=~"[A-Za-z.]+[A-Za-z.-]+(presto.)+(worker)"}) BY (presto_failuredetector_HeartbeatFailureDetector_ActiveCount) < 0.90

Notice the ~ after instance=

Yaniv Hakim
  • 77
  • 10