Querying counter "since"

1,174 views
Skip to first unread message

robu...@gmail.com

unread,
Oct 11, 2017, 7:08:47 AM10/11/17
to Prometheus Users
Hi,
new to prometheus I struggle to figure out 
how do I querry for the sum of a counter value SINCE a given time, such as "today 00:00"

let's take the counter "node_network_receive_bytes" from node-exporter as an example here:

node_network_receive_bytes{instance="mybox", device="eth0"}

gives me the total amount of bytes received on "eth0" since instance "mybox" started.
But we want graphs that show the total amount of bytes received SINCE LAST MIDNIGHT,
meaning each day at 00:00 our graphs should start with value 0 again and going up only until 23:59:59


any hint is appreciated!
TIA

robu...@gmail.com

unread,
Oct 12, 2017, 4:49:12 AM10/12/17
to Prometheus Users
Anybody???

Conor Broderick

unread,
Oct 12, 2017, 6:51:06 AM10/12/17
to robu...@gmail.com, Prometheus Users
You can use the increase() query function to evaluate the increase of your counter over a given time frame (increase(node_network_receive_bytes[24h])), however as you're looking to see the increase from a specific time this doesn't really solve your problem.

I think you may be better off re-evaluating why you're trying to do this. Could you explain your use case?

It's normally better to take the rate of increase of a counter to get the per hour increase etc.


--
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/ef74c945-19d4-4909-a7cd-54ec72017529%40googlegroups.com.

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



--

robu...@gmail.com

unread,
Oct 12, 2017, 8:48:26 AM10/12/17
to Prometheus Users
thnx Conor

true, "increase" doesn't help as you see.

Use case here is "the boss" who want's  nice graphs over the usage of our printers.
How many pages, when, on which printer. 
(node_network_receive_bytes was only an example to make the question more common)

Since in this special case total accuracy on the offset time wouldn't  be important (since nobody uses the printers between 00:00 and 01:00)
I would be happy with a simple "... offset hour()" 
even better though would be an "... offset (hour()*60+minute())m"

value_now - value offset (hour()*60+minute())m

would be the amount since last 00:00

puzzling that nobody seems to need a "value since a given point in time" ...



On Thursday, October 12, 2017 at 12:51:06 PM UTC+2, Conor Broderick wrote
You can use the increase() query function to evaluate the increase of your counter over a given time frame (increase(node_network_receive_bytes[24h])), however as you're looking to see the increase from a specific time this doesn't really solve your problem.

I think you may be better off re-evaluating why you're trying to do this. Could you explain your use case?

It's normally better to take the rate of increase of a counter to get the per hour increase etc.

On 12 October 2017 at 09:49, <robu...@gmail.com> wrote:
Anybody???

On Wednesday, October 11, 2017 at 1:08:47 PM UTC+2, robu...@gmail.com wrote:
Hi,
new to prometheus I struggle to figure out 
how do I querry for the sum of a counter value SINCE a given time, such as "today 00:00"

let's take the counter "node_network_receive_bytes" from node-exporter as an example here:

node_network_receive_bytes{instance="mybox", device="eth0"}

gives me the total amount of bytes received on "eth0" since instance "mybox" started.
But we want graphs that show the total amount of bytes received SINCE LAST MIDNIGHT,
meaning each day at 00:00 our graphs should start with value 0 again and going up only until 23:59:59


any hint is appreciated!
TIA

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



--

Nicholas Capo

unread,
Oct 12, 2017, 10:34:26 AM10/12/17
to robu...@gmail.com, Prometheus Users

Are you using Grafana?
It supports showing graphs of "today".

Nicholas


Ben Kochie

unread,
Oct 12, 2017, 11:23:05 AM10/12/17
to Nicholas Capo, robu...@gmail.com, Prometheus Users
There has also been some ideas/work to add various internal template variables in Grafana to let you pass graph/step width to queries to better support this kind of use case.

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.

--
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/CAKA4%2B6qy%3DySORC%3D%3DeHEqHNiZfj7MB-%3D1dpDLdYatn1rgp_TDFQ%40mail.gmail.com.

Ben Kochie

unread,
Oct 12, 2017, 11:27:47 AM10/12/17
to robu...@gmail.com, Prometheus Users
On Thu, Oct 12, 2017 at 2:48 PM, <robu...@gmail.com> wrote:
thnx Conor

true, "increase" doesn't help as you see.

Use case here is "the boss" who want's  nice graphs over the usage of our printers.
How many pages, when, on which printer. 
(node_network_receive_bytes was only an example to make the question more common)

Since in this special case total accuracy on the offset time wouldn't  be important (since nobody uses the printers between 00:00 and 01:00)
I would be happy with a simple "... offset hour()" 
even better though would be an "... offset (hour()*60+minute())m"

value_now - value offset (hour()*60+minute())m

would be the amount since last 00:00

puzzling that nobody seems to need a "value since a given point in time" ...

It's not that people don't ask for this, but the difficulty is that it's more of a display use case than a query case.  What you're asking for is possible, but requires a but of custom API work that isn't in the usual "show me a graph" use case that people more commonly want.  I have written a number of "report" scripts using python and the Prometheus API.

Grafana can let you solve a lot of these issues.  As someone said below, you can have the graph default to displaying "since today", and then you can craft a graph that displays "prints per hour" with a query of "increase(prints_total[1h])".  Then you can have Grafana display the total of prints that day in a table below the graph.

Depending on the printer, or print manager, you may be able to get the actual print page counts per printer via SNMP.
 
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/85c25557-0a47-42b4-9849-813471dcfb7f%40googlegroups.com.

robu...@gmail.com

unread,
Oct 13, 2017, 6:25:33 AM10/13/17
to Prometheus Users
thnx Ben,

I see.
played a little with grafana and found a good (enough) solution indeed.
A combination between between the total number and "today so far" diplay plus the increase value on the second y-ax.

thnx for the help again!

robu...@gmail.com

unread,
Oct 13, 2017, 6:26:06 AM10/13/17
to Prometheus Users
Reply all
Reply to author
Forward
0 new messages