JIMMY'S WAY
|
DEV.jimmysway
dev-blogs
|
grafana-prometheus-query-tips---bounding-things-to-zero-at-the-start

miscellaneous

SOCIALS

February 9, 2026
Tips
WRITTEN BY
JIMMY SUI

I have a problem. I wanna see my monthly resource, GPU, CPU, RAM etc. usage for my own internal service. Easy enough right? Yeah it is easy but it is also a bit clumsy and unintuitive the way it looks right now.

Monthly usage for GPU, CPU and RAM can be queried in Prometheus but the graph produced is not intuitive as it will mostly likely produce a rolling 30d window whereby every data point is the total from 30d earlier. While this can be useful to track changes in resource usage per month, it is not particularly useful for any who want to track usage within the month to see how much resources they're using.

Here's what we don't want. Every point along this curve is the sum of all values in the targeted range which is clumsy.

Intuitively we want a solution that shows the month-to-date increases in resource usage and we want to bound the beginning of the month to zero as a sort of starting point. To do this, we can use the in built Grafana Transformations specifically the Cumulative Sum Transform whilst querying with the $__interval parameter so that the cumulative function does not over count every data point. The result is something like this:

Here it is clear.  That I'm starting at 0 and this is how everything increased month-to-date

The solution is something like this:

For this gauge metric in this case we are summing all points that have read above 0.

And for counter metrics:

For counter metrics we are using the increase() function instead of count_over_time()

Existing Issues and Limitations

Window sizing (max data points) causes inconsistencies with the cumulative transform can cause the values of the cumulative transform and the values of the actual $__range query to diverge by around in my testing around +/- 10% in the worst cases. It happens only in quite rare circumstances where the data is not quite granular enough to get an accurate cumulative summation.

Heading 1

Heading 2

Heading 3

Heading 4

Heading 5
Heading 6

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Block quote

Ordered list

  1. Item 1
  2. Item 2
  3. Item 3

Unordered list

  • Item A
  • Item B
  • Item C

Text link

Bold text

Emphasis

Superscript

Subscript

asdsa