Grafana label_values regex to capture uri without query parameter

huangapple go评论50阅读模式
英文:

Grafana label_values regex to capture uri without query parameter

问题

label_values(http_client_requests_seconds_count, uri)

英文:

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

答案1

得分: 1

我明白你的请求。以下是翻译好的部分:

你应该使用 Regex: (.*?)(\?.*)?(位于查询右下方的字段)

它将从你的数值中移除 ? 和后面的所有内容,并在此之后应用不同的方法。

你无法通过查询来实现这一点,主要是因为即使 label_values 严格来说不是 Prometheus 查询的一部分。label_values 是 Grafana 用于从 Prometheus(以及类似的系统)指标中提取标签的函数。

英文:

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.

huangapple
  • 本文由 发表于 2023年4月6日 21:39:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/75950213.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定