Count how many times an event occurred or a metric was reported using PromQL

1.5k views Asked by At

I use Victoria Metrics to track IOT Devices. Whenever device connects/disconnects i insert a metric into Victoria Metrics. My metric name is devcon_s. i can query data using this - devcon_s{device_id="something"}

But I want to know how frequent device disconnect in a day. I trie queries like this - sum_over_time(count_values without(kd_id) ("value", devcon_s{kd_id="something"} == 0)[1d:]) or

count_over_time((devcon_s{kd_id="something"} == 0)[1d:])

With step equal to 1d or 1h. But it doesnt give me actual number of count the event was reported but something else which doesnt make sense to me. Am i doing something wrong ? Or is it not possible to count actual number of values in promQL

1

There are 1 answers

0
valyala On

MetricsQL provides count_le_over_time(m[d], le) function, which returns the number of raw data points that have values smaller or equal to le on the time range [d] for each time series matching m.

The following query should return the number of raw data points with value<=0 for the last day:

count_le_over_time(devcon_s{k_id="something"}[1d])