英文:
Create a count on a Grafana Dashboard
问题
我是新来的 Grafana 用户,正在创建一个仪表板。我需要显示一个指标的计数。以下是生成的数据:
我想要创建一个按独特的 deploymentId 计数 name 的计数。例如,在上面的图像中有两个 deploymentId,分别是 187 和 191。所以,计数应该显示为 2。
我已经编写了以下查询,但结果显示为 0。
("count", rate(name{tenant=~"$Agencies"}[$__rate_interval]))
注意:Agencies 是仪表板顶部的筛选器。计数应该能够根据选择的 Agencies 更改而进行筛选。能否请您帮助我解决这个问题?
英文:
I am new the Grafana and I am creating a dashboard. I need to show the count of a metric. Below is the data generated for it:
I want to create a count of the name per unique deploymentId. For e.g. in the image above there are 2 deploymentId's 187 and 191. So, the count should show 2.
I have written the below query for it, but I am getting 0 as the result.
("count", rate(name{tenant=~"$Agencies"}[$__rate_interval]))
Note: Agencies is a filter at the top of the Dashboard. The count should be able to filter based on the change in the selection of Agencies.
Can I please get help on this?
答案1
得分: 1
要计算不同标签值的数量,您可以使用 count(count by(label) (...)
结构。 (严格来说,内部聚合可以是任何带有 by(label)
子句的内容)
要计算仪表板选择的时间范围内的值,而不是最后的5分钟(过时窗口),我们需要"延展"值,以便它们包含在计算中。这可以通过使用 last_over_time
来完成。
您的最终查询将如下所示:
count(count by(deploymentId) (last_over_time(name{tenant=~"$Agencies"}[$__range])))
请注意,不清楚您是否有名为 name
的度量标签。我假设您有基于您的尝试。如果没有 - 请使用具有标签 deploymentId
和 tenant
的任何度量标签。
英文:
To calculate number of distinct label values you can use count(count by(label) (...)
construct. (Strictly speaking inner aggregationcan be anything with by(label)
clause)
To calculate over time range selected for dashboard, and not the last 5 minutes (staleness window) we need to "stretch" values so they are included in calculation. It can be done with last_over_time
.
Your final query will look like this:
count(count by(deploymentId) (last_over_time(name{tenant=~"$Agencies"}[$__range]))
Notice, it's not clear if you have metric named name
. I assume that you do based on your attempt. If no - use any metric with labels deploymentId
and tenant
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论