Sum over range vector?

15,200 views
Skip to first unread message

Dave Cadwallader

unread,
Jan 3, 2018, 12:55:08 PM1/3/18
to Prometheus Users
Let's say I have a gauge called "foo".  I can get the sum of all values of foo since the beginning of time using:

sum(foo)

But let's say I want to get the sum of all values of foo, from the past 5 min.  I tried:

sum(foo[5m])

...but I got an error: "expected type instant vector in aggregation expression, got range vector"

Is there a way to sum across a range vector, or a different approach to achieve my goal?

Thanks!

Dave Cadwallader

unread,
Jan 3, 2018, 12:59:12 PM1/3/18
to Prometheus Users
Just realized that sum(foo) doesn't give me the sum of all values since the beginning of time, but only the most recent value.  So I think I have a misunderstanding about how sum works.

Ben Kochie

unread,
Jan 3, 2018, 1:03:15 PM1/3/18
to Dave Cadwallader, Prometheus Users
You can use sum_over_time(foo[5m]) to add up all the values in a metric over time.

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-users+unsubscribe@googlegroups.com.
To post to this group, send email to prometheus-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/3f5d5205-5f82-446f-8abe-4a4a4e396e7a%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Dave Cadwallader

unread,
Jan 3, 2018, 1:10:44 PM1/3/18
to Prometheus Users
Brilliant! I somehow missed this in the docs, but I see it now.  Thanks.  


On Wednesday, January 3, 2018 at 11:03:15 AM UTC-7, Ben Kochie wrote:
You can use sum_over_time(foo[5m]) to add up all the values in a metric over time.
On Wed, Jan 3, 2018 at 6:59 PM, Dave Cadwallader <dcadwa...@gmail.com> wrote:
Just realized that sum(foo) doesn't give me the sum of all values since the beginning of time, but only the most recent value.  So I think I have a misunderstanding about how sum works.

On Wednesday, January 3, 2018 at 10:55:08 AM UTC-7, Dave Cadwallader wrote:
Let's say I have a gauge called "foo".  I can get the sum of all values of foo since the beginning of time using:

sum(foo)

But let's say I want to get the sum of all values of foo, from the past 5 min.  I tried:

sum(foo[5m])

...but I got an error: "expected type instant vector in aggregation expression, got range vector"

Is there a way to sum across a range vector, or a different approach to achieve my goal?

Thanks!

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To post to this group, send email to promethe...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages