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?
To calculate number of distinct label values you can use count(count by(label) (...))
construct. (Strictly speaking inner aggregation can 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 not - use any metric with labels deploymentId
and tenant
.