Computing aggregates on a per-month/week/day basis (not trailing)?

10,762 views
Skip to first unread message

Mario

unread,
May 25, 2018, 6:41:15 PM5/25/18
to Prometheus Users
Hi,

I'm looking for a way to query Prometheus for total bytes transferred in a given pay period (typically, the current month). This would be connected to a Grafana graph displaying the usage -- it would be increasing each month, and then reset when the next month begins, etc. The measurements come from node_exporter's node_network_transmit_bytes metrics (a counter of bytes transferred).

My problem is that I'm not exactly sure how to write the query that will give me the utilization in the _current_ month, rather than in the trailing 30 days? I can observe the utilization over the trailing 30 days with a query such as:

   increase(node_network_transmit_bytes{device="eth0"}[30d])

But how would I write a query for "increase over the current month" (month of the time the expression is evaluated)? Or over a different time period (say, week, or day)?

I'm rather new PromQL, so I apologize if I'm asking an obvious question. I did try to google for the answer, but wasn't very successful.

PS: Given this is my first post here, I also want to thank you for writing and making Prometheus available! We're deploying it as a part of a system that monitors the sky for astronomical transient events (from new asteroids to supernovae).

Regards,
-- Mario

Ben Kochie

unread,
May 26, 2018, 2:40:11 AM5/26/18
to Mario, Prometheus Users
Grafana doesn't exactly support this kind of query with Prometheus.

The best workaround is to use a graph of `increase(node_network_transmit_bytes{device="eth0"}[$__interval])` and use the "Total" feature in the legend.

Then change the time range of the graph to "This month"

--
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/8e025d9b-ce12-4bc7-910c-a1d33285707f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mario

unread,
May 29, 2018, 3:58:03 PM5/29/18
to Prometheus Users
Thanks for the advice!

This workaround doesn't work well for our use case, as our main dashboard is generally fixed to ~past 24hrs. What I ended up doing was computing the totals using an external script and loading them as a separate time series.

It'd be great if Prometheus/Grafana gained support this type of query -- we see a need for it quite frequently (have many queries where the interval of interest isn't trailing, but past day, past week, etc.).

Thanks again!
- M.


On Friday, May 25, 2018 at 11:40:11 PM UTC-7, Ben Kochie wrote:
Grafana doesn't exactly support this kind of query with Prometheus.

The best workaround is to use a graph of `increase(node_network_transmit_bytes{device="eth0"}[$__interval])` and use the "Total" feature in the legend.

Then change the time range of the graph to "This month"
On Sat, May 26, 2018 at 12:41 AM, Mario <maj...@gmail.com> wrote:
Hi,

I'm looking for a way to query Prometheus for total bytes transferred in a given pay period (typically, the current month). This would be connected to a Grafana graph displaying the usage -- it would be increasing each month, and then reset when the next month begins, etc. The measurements come from node_exporter's node_network_transmit_bytes metrics (a counter of bytes transferred).

My problem is that I'm not exactly sure how to write the query that will give me the utilization in the _current_ month, rather than in the trailing 30 days? I can observe the utilization over the trailing 30 days with a query such as:

   increase(node_network_transmit_bytes{device="eth0"}[30d])

But how would I write a query for "increase over the current month" (month of the time the expression is evaluated)? Or over a different time period (say, week, or day)?

I'm rather new PromQL, so I apologize if I'm asking an obvious question. I did try to google for the answer, but wasn't very successful.

PS: Given this is my first post here, I also want to thank you for writing and making Prometheus available! We're deploying it as a part of a system that monitors the sky for astronomical transient events (from new asteroids to supernovae).

Regards,
-- Mario

--
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.

Alin Sînpălean

unread,
May 30, 2018, 6:15:30 AM5/30/18
to Prometheus Users
Here's something to get you started:

    process_start_time_seconds{job="prometheus"} and (month(timestamp(process_start_time_seconds{job="prometheus"})) == 4)

It produces all the process_start_time_seconds samples collected in the month of April. You can tweak it for last month or (with some hardcoded relabeling) all months. Unfortunately I don't think there is a way of dynamically assigning labels based on values, so you can't go from e.g. month(timestamp(foo)) to foo:increase_1mon{year="2018",month="4"} without hardcoding "2018" and "4" some place or other.

Cheers,
Alin.
Reply all
Reply to author
Forward
0 new messages