在Grafana仪表板上创建一个计数。

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

Create a count on a Grafana Dashboard

问题

我是新来的 Grafana 用户,正在创建一个仪表板。我需要显示一个指标的计数。以下是生成的数据:

在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:

在Grafana仪表板上创建一个计数。

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 的度量标签。我假设您有基于您的尝试。如果没有 - 请使用具有标签 deploymentIdtenant 的任何度量标签。

英文:

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.

huangapple
  • 本文由 发表于 2023年7月27日 23:11:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76781145.html
匿名

发表评论

匿名网友

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

确定