如何从Grafana变量中创建常规表达。涌入2.0dB

发布于 2025-01-23 23:36:21 字数 904 浏览 1 评论 0原文

我有这个查询,可以从git中获取分支信息。我希望能够通过变量“史诗”过滤数据。在Grafana中,我从数据库中获取了史诗数据,可以从下拉列表中的每个Epic(MultiSelect)中选择它。

from(bucket: "my_bucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "my_measure")
  |> filter(fn: (r) => r["_field"] == "Score")
    |> filter(fn: (r) => r["epic"] == "${epic_db}")
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: "mean")

但是,当我在列表中选择多个史诗时,我得到了:

    |> filter(fn: (r) => r["epic"] == "{epic-1,epic-2}")

它不像Squl中的SQL(epic1,epic2等)那样工作。 对我有用的是,

filter(fn: (r) => r["epic"] =~ /epic1|epic2|epic3/

要通过使用此下拉列表检查列表和Grafana中的变量来构建这样的正则是这样,但我不知道如何构建这样的正则命令。我正在尝试所有类似的事情:

 "/${epic_db}/"

但是没有工作。有什么想法,如何使用Flux的InfuxDB2.0使其成为可能?

I have this query that pulls branch information from GIT. I would like to be able to filter the data by the variable "epic". In Grafana, I have the epic data pulled from the database and it can be selected from a dropdown list witch checkbox for each epic (multiselect).

from(bucket: "my_bucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "my_measure")
  |> filter(fn: (r) => r["_field"] == "Score")
    |> filter(fn: (r) => r["epic"] == "${epic_db}")
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: "mean")

But when i select more than one epic on list, i got this:

    |> filter(fn: (r) => r["epic"] == "{epic-1,epic-2}")

Which is not working like the SQL IN statement (WHERE epic IN (epic1, epic2, etc).
The thing that is working for me, is to build the regex like this

filter(fn: (r) => r["epic"] =~ /epic1|epic2|epic3/

But i have no idea, how to build such a regex, by using this drop-down-check-list with variables in Grafana. I was trying all that stuff like:

 "/${epic_db}/"

But is not working. Any ideas, how to make it possible using InfluxDB2.0 with Flux?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天暗了我发光 2025-01-30 23:36:22

请查看可变格式选项文档 >。

基本上Grafana允许您选择查询中的变量格式。在您的情况下,您可以执行这样的操作:

from(bucket: "my_bucket")
 |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
 |> filter(fn: (r) => r["_measurement"] == "my_measure")
 |> filter(fn: (r) => r["_field"] == "Score")
 |> filter(fn: (r) => r["epic"] =~ /${epic_db:regex}/)
 |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
 |> yield(name: "mean")

这样,您可以在通量查询语言的Regex功能中使用构建。

Have a look at the variable formatting options documentation here.

Basically grafana allows you to choose how the variable is formatted in your query. In your case you can do something like this:

from(bucket: "my_bucket")
 |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
 |> filter(fn: (r) => r["_measurement"] == "my_measure")
 |> filter(fn: (r) => r["_field"] == "Score")
 |> filter(fn: (r) => r["epic"] =~ /${epic_db:regex}/)
 |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
 |> yield(name: "mean")

This way you can use the build in regex functionality of the flux query language.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文