Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prometheus doesn't match regex query

I'm trying to write a prometheus query in grafana that will select visits_total{route!~"/api/docs/*"}

What I'm trying to say is that it should select all the instances where the route doesn't match /api/docs/* (regex) but this isn't working. It's actually just selecting all the instances. I tried to force it to select others by doing this: visits_total{route=~"/api/order/*"} but it doesn't return anything. I found these operators in the querying basics page of prometheus. What am I doing wrong here?

like image 926
ninesalt Avatar asked Feb 21 '19 18:02

ninesalt


People also ask

What regex does Prometheus use?

All regular expressions in Prometheus use RE2 syntax.

How do you use the wildcard in Prometheus query?

Wildcards in queries Prometheus uses a Regex-like pattern and the wildcard character is . + (read: dot plus) combined with tilde character ( ~ ) instead of just the equal sign ( = ). So the query becomes http_status{job~="customer-. +"} .

How to see Prometheus metrics in Grafana?

Click the graph title, then click "Edit". Under the "Metrics" tab, select your Prometheus data source (bottom right). Enter any Prometheus expression into the "Query" field, while using the "Metric" field to lookup metrics via autocompletion.


1 Answers

May be because you have / in the regex. Try with something like visits_total{route=~".*order.*"} and see if the result is generated or not.

Try this also,

visits_total{route!~"\/api\/docs\/\*"}

If you want to exclude all the things that has the word docs you can use below,

visits_total{route!~".*docs.*"}
like image 164
prime Avatar answered Sep 20 '22 13:09

prime