prometheus doesn't match regex query

ninesalt picture ninesalt · Feb 21, 2019 · Viewed 17.9k times · Source

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?

Answer

prime picture prime · Feb 21, 2019

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.*"}