Search code examples
prometheusgrafana

Grafana label_values regex to capture uri without query parameter


I've created a repeating panel per API that my application calls, showing the http status returned.

The query that I could write for the variable so far is:

label_values(http_client_requests_seconds_count, uri)

And the selector is populated with URIs like:

/user/accounts
/user/contact_info
/account/details?accnr=1234
/account/details?accnr=5678

How should the query look like in order to omit the query parameter and get the result as:

/user/accounts
/user/contact_info
/account/details

Solution

  • You should use Regex: (.*?)(\?.*)? (field located right under Query)

    It will remove ? and everything what follows it from your values. And also applies distinct after it.

    You can't do this through query, mostly because even label_values is not part of query to Prometheus strictly speaking. label_values is Grafana's function for extraction of labels from Prometheus' (and alike) metrics.