PromQL sum from beginning of month - i.e traffic consumer during billing period

Hello!
I’ve set up a free vps, and have prometheus + node exporter on it, so I can have panel that shows node_network_transmit_bytes_total

What I want is to be able to check that server hasn’t consumed more than 5Tb of traffic during any particular month.
(And ideally to get me alerts for that metric)

Currently best I could do is “increase(node_network_transmit_bytes_total{device!=“lo”}[30d])”
but that is not what I really want, since on the day 35 it would show “how much traffic was consumen in the last 30 days” and that would include traffic from 1st billable period, from day 5 to day 30.

I couldn’t even find this exact question anywhere, so it kind of seems that either no one before wanted this kind of monitoring or it is somehow trivial to set up in a way I can’t seem to see.

I’ve tried reading on time ranges, but offset doesn’t seem to be what I want
and time durations seem to only be fixed to [now - X, now] where X is value “s, m, d, w” etc

I know that grafana can express “previous week” and “this month so far” as it’s dashboard setting, but I don’t know if that’s something that can be used in the PromQL query.

Could you help me figure out a way to set this up?

This sort of thing is down to whatever tool you are using to generate reports, dashboards, etc. The important thing is for the dates used for the query to be what you want. Prometheus will happily run your query over whatever range you ask it, so you need to ensure that isn’t just “now” or “now back to a week ago” but instead set to something more specific (e.g. “5th January 2022 midnight to 25th January 2022 2am”)

1 Like

I’ve spent a lot more time trying to figure out whether “non running increase” is possible with Grafana+Prometheus
i.e so that increase would get counted from start of month, or start of week, and not with running window (t-30d, t)

And I still haven’t found any way to do that.
Here:

it’s stated that Grafana can’t make such requests to prometheus, and it seems that with creating dashboards via python api it’s possible, but not with Grafana.

I’ve tried looking into strange queries like (my_metric - my_metric offset $__range + day_of_month(my_metric))
but offset doesn’t seem to be able to take calculated value

For some reason the comment from stackoverflow states that for Victoria Metrics there’s function available in grafana range_first
that would have definitely helped if it were available for prometheus, I dont’ understand why would it not be available, it seems to be function that should work on the side of Grafana

But overall, I’m very close to giving up