prometheusvictoriametrics

Get Datapoint Count of a Prometheus Timeseries


I have defined a recording rule for a Prometheus expression.

Rule - rule:my_recording_rule
Expression - sum by(foo) (increase(some_metric{}[4w]))

That recording rule contains data every 15 seconds. So if we take 1 minute there are 4 data points recorded.

I want to get the total datapoint count in that recording rule.

I tried count(rule:my_recording_rule) but it only gives me the number of Timeseries listed.

I want to get the data point count of each timeseries.


Solution

  • You need to use count_over_time function. For example, the following query will return the number of raw sample during the last hour per each time series with some_metric name:

    count_over_time(some_metric[1h])
    

    If you need to sum datapoints across matching time series, then just wrap the query into sum:

    sum(count_over_time(some_metric[1h]))