使用Elasticsearch数据源按日期时间字段的存在对Grafana图表进行分组。

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

Group Grafana chart by presence of a datetime field with Elasticsearch datasource

问题

我有一个Elasticsearch数据源,其中有一个名为aborted_at的字段。这是一个ISO-8601时间戳,仅在某些记录中存在。

我想创建一个堆叠到100%的条形图,显示随时间变化的已完成和已中止记录的比例。

我的查询是一个简单的过滤器:

type.keyword = "$measurement_type"

我将分组设置为terms和日期直方图。但我只能按aborted_at的实际值分组:

英文:

I have an Elasticsearch datasource with a field called aborted_at. It’s an ISO-8601 timestamp, and it is only present for some records.

I want to create a bar chart, stacked to 100%, that shows the proportion of finished and aborted records over time.

My query is a simple filter:

type.keyword = "$measurement_type"

and I’ve set my grouping to terms and date histogram. But I can only group by the actual values of aborted_at:

使用Elasticsearch数据源按日期时间字段的存在对Grafana图表进行分组。

I would like to be able to group by (pseudocode) empty(aborted_at) or whatever possible solution to turn the field into a binary one (i.e., present or not).

I can get this relatively easily within Kibana’s Lens visualization:

使用Elasticsearch数据源按日期时间字段的存在对Grafana图表进行分组。

… but I don't see how to do that with Grafana's Elasticsearch datasource queries.

<sub>This is a cross-post from the Grafana discussion board. I will keep both posts updated when a solution is found.</sub>

答案1

得分: 1

在你的面板中创建两个查询:

  • type.keyword: &quot;$measurement_type&quot; AND (_exists_:&quot;aborted_at&quot;),别名为 Aborted,
  • type.keyword: &quot;$measurement_type&quot; AND !(_exists_:&quot;aborted_at&quot;),别名为 finished。

两者都使用 Metric(1) Count。按 日期直方图 分组;第一个使用 aborted_at,第二个使用包含完成日期的字段。

然后在面板选项中选择条形图 > 堆叠 > 100%。

在结果中,你会得到类似的图表。

英文:

In your panel create two queries:

  • type.keyword: &quot;$measurement_type&quot; AND (_exists_:&quot;aborted_at&quot;) with alias Aborted,
  • type.keyword: &quot;$measurement_type&quot; AND !(_exists_:&quot;aborted_at&quot;) with alias finished.

Both with Metric(1) Count. Group by Date Histogram; aborted_at for the first one, field containing finish date for second one.

Then in Panel options > Bar chart > Staking select 100%.

In the result you'll get something like
使用Elasticsearch数据源按日期时间字段的存在对Grafana图表进行分组。

huangapple
  • 本文由 发表于 2023年4月11日 16:09:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75983728.html
匿名

发表评论

匿名网友

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

确定