英文:
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
:
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:
… 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: "$measurement_type" AND (_exists_:"aborted_at")
,别名为 Aborted,type.keyword: "$measurement_type" AND !(_exists_:"aborted_at")
,别名为 finished。
两者都使用 Metric(1)
Count
。按 日期直方图
分组;第一个使用 aborted_at
,第二个使用包含完成日期的字段。
然后在面板选项中选择条形图 > 堆叠 > 100%。
在结果中,你会得到类似的图表。
英文:
In your panel create two queries:
type.keyword: "$measurement_type" AND (_exists_:"aborted_at")
with alias Aborted,type.keyword: "$measurement_type" AND !(_exists_:"aborted_at")
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%.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论