Count/display label dimensions with a certain value?

176 views
Skip to first unread message

John Dexter

unread,
Mar 18, 2021, 8:27:58 AM3/18/21
to promethe...@googlegroups.com
I have metrics provided by several processes:

subsystem_connected{subsystem="ABC"}

This has a value of 0 or 1, and each process has a different subsystem label. Within Grafana, I want to do a couple of things:

- Display a count how many are connected (value=1)
- Display the list of subsystem values where value=1

I keep thinking I've got it with functions like count_value, etc, but end up just displaying the number of labels regardless of metric value.
Can anyone help me with sample PromQL queries?

Many thanks.

Stuart Clark

unread,
Mar 18, 2021, 9:34:56 AM3/18/21
to John Dexter, promethe...@googlegroups.com
For the first you'd want to use "sum", which would add up the values. As
they are either 0 or 1, that would give you the total number of time
series which have a value of 1, meaning the number connected.

For the second you just want to do a simple "metric = 1" query which
will return all time series which have the value of 1. You can then
format that within Grafana as a table for example with the subsystem label.

--
Stuart Clark

Reply all
Reply to author
Forward
0 new messages