Query calculation help

71 views
Skip to first unread message

Dmitry

unread,
May 10, 2020, 8:11:50 AM5/10/20
to Prometheus Users
Hi guys!
I am new to prometheus and having some difficulties with it and have already become a little confused.
I am trying to calculate the amount of incoming traffic for an interface for all the time in megabytes, which is displayed in octets.
Please correct, what am I doing wrong?
P.S. sorry for my English.

ifHCInOctets{ifDescr="ether1",ifIndex="3",ifName="ether1",instance="10.10.4.102",job="snmp"}  value=1433610926 this is how query looks in prom.

sum(ifHCInOctets{ifDescr="ether1",ifName="ether1",instance="10.10.4.102",job="snmp"})/1000000 and i'm trying to calculate sum of traffic.
As a result, my value=1433.610926


Julius Volz

unread,
May 10, 2020, 1:38:34 PM5/10/20
to Dmitry, Prometheus Users
Hi Dmitry,

ifHCInOctets is a counter metric, which can reset to 0 at arbitrary times (like when your networking device restarts), so you cannot rely on its latest value to show you the total cumulative count of bytes over "all time". So with counters, you almost never want to look at their absolute value, but at their rate of increase (with resets handled by functions such as rate() or increase()).

For example, you could do:

    increase(ifHCInOctets{ifDescr="ether1",ifIndex="3",ifName="ether1",instance="10.10.4.102",job="snmp"}[7d]) / 1e6

...to calculate the total MB (in base 10) over 7d. Set the "7d" to a time range which is sufficient to mean "all time" for you, and you should get the increase you're looking for.

I don't think you will need the "sum(...)" at all if you are selecting only one time series to begin with (looks like exactly one interface on one node). sum(...) would be for summing the values of multiple time series at one point in time.

Regards,
Julius

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/4f1d1f2d-4224-4cc6-9d00-cf0736a78732%40googlegroups.com.


--
Julius Volz
PromLabs - promlabs.com

Dmitry

unread,
May 14, 2020, 6:44:21 AM5/14/20
to Prometheus Users
Thank you.

Dmitry

unread,
May 15, 2020, 5:04:58 AM5/15/20
to Prometheus Users
What a strange situation. If you transfer the formula to grafana and die in time intervals, then the increase in 6 hours goes beyond more than 12.
Nevertheless, if we consider the total traffic not on the interface, but on the device, can we take mikrotik_interface_rx_byte and calculate sum?


On Sunday, May 10, 2020 at 8:38:34 PM UTC+3, Julius Volz wrote:
Hi Dmitry,

ifHCInOctets is a counter metric, which can reset to 0 at arbitrary times (like when your networking device restarts), so you cannot rely on its latest value to show you the total cumulative count of bytes over "all time". So with counters, you almost never want to look at their absolute value, but at their rate of increase (with resets handled by functions such as rate() or increase()).

For example, you could do:

    increase(ifHCInOctets{ifDescr="ether1",ifIndex="3",ifName="ether1",instance="10.10.4.102",job="snmp"}[7d]) / 1e6

...to calculate the total MB (in base 10) over 7d. Set the "7d" to a time range which is sufficient to mean "all time" for you, and you should get the increase you're looking for.

I don't think you will need the "sum(...)" at all if you are selecting only one time series to begin with (looks like exactly one interface on one node). sum(...) would be for summing the values of multiple time series at one point in time.

Regards,
Julius

On Sun, May 10, 2020 at 2:11 PM Dmitry <barnyb...@gmail.com> wrote:
Hi guys!
I am new to prometheus and having some difficulties with it and have already become a little confused.
I am trying to calculate the amount of incoming traffic for an interface for all the time in megabytes, which is displayed in octets.
Please correct, what am I doing wrong?
P.S. sorry for my English.

ifHCInOctets{ifDescr="ether1",ifIndex="3",ifName="ether1",instance="10.10.4.102",job="snmp"}  value=1433610926 this is how query looks in prom.

sum(ifHCInOctets{ifDescr="ether1",ifName="ether1",instance="10.10.4.102",job="snmp"})/1000000 and i'm trying to calculate sum of traffic.
As a result, my value=1433.610926


--
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 promethe...@googlegroups.com.

Brian Candler

unread,
May 15, 2020, 6:02:08 AM5/15/20
to Prometheus Users
On Friday, 15 May 2020 10:04:58 UTC+1, Dmitry wrote:
What a strange situation. If you transfer the formula to grafana and die in time intervals, then the increase in 6 hours goes beyond more than 12.

I'm afraid that "increase" is effectively "rate" multiplied up to fit the entire time range:

The increase is extrapolated to cover the full time range as specified in the range vector selector

 
Nevertheless, if we consider the total traffic not on the interface, but on the device, can we take mikrotik_interface_rx_byte and calculate sum?

sum by (instance) ( increase(...) ) 

will group together all interfaces on the device and give you a separate sum for each device.

Dmitry

unread,
May 15, 2020, 7:46:41 AM5/15/20
to Prometheus Users
Can you show the noob please, how the formula should look? Now nothing happens at all.

Brian Candler

unread,
May 15, 2020, 8:45:21 AM5/15/20
to Prometheus Users
On Friday, 15 May 2020 12:46:41 UTC+1, Dmitry wrote:
Can you show the noob please, how the formula should look? Now nothing happens at all.


Please show the formula you're using.

Dmitry

unread,
May 15, 2020, 8:50:22 AM5/15/20
to Prometheus Users
(increase(mikrotik_interface_tx_byte{address="$node",instance="212.90.175.74:9436"}[7d])) /1e6
(increase(ifHCInOctets{address="$node",instance="212.90.175.74:9436"}[7d])) /1e6

Brian Candler

unread,
May 15, 2020, 1:53:07 PM5/15/20
to Prometheus Users
On Friday, 15 May 2020 13:50:22 UTC+1, Dmitry wrote:
(increase(mikrotik_interface_tx_byte{address="$node",instance="212.90.175.74:9436"}[7d])) /1e6
(increase(ifHCInOctets{address="$node",instance="212.90.175.74:9436"}[7d])) /1e6


And you're saying those formulae give no results?

Sorry I don't know, they look OK to me. assuming that $node and instance are set correctly.

Note: it's not very convenient to have two different labels which are both used to select the host.  You may be better off putting the label you want in the "instance" label. See:

Reply all
Reply to author
Forward
0 new messages