1

I am working on a project to monitor the network devices by the help of SNMP and MRTG, RRDTool. As part of bandwidth monitoring, I can be able to get the maximum used bandwidth per time resolution.

Meanwhile, I need to maintain a history of total data usage volume. I knew it is possible to get from vnStat. But I don't know how to achieve this with SNMP.

Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227
Muneer
  • 142
  • 10

1 Answers1

2

The way you get bandwidth from SNMP is by querying a counter, preferably the 64-bit ones (ifHCInOctets, ifHCOutOctets). You then query the same counter a known time period later, and do the simple math (where c₁ is the first count, and c₂ the second):

\mathrm{bandwidth} = \frac{c_2 - c_1}{t_2 - t_1}

There are then two way to get the total bytes:

  1. Just use the counter. It'll be accurate to the last time the counter was reset—often only when the network gear is rebooted (though more often is possible).

  2. Integrate the bandwidth over time. Or, more simply put, if you have the average bandwidth for the month and multiply it by the length of the month, you get the total bandwidth (with some rounding error, no doubt).

derobert
  • 107,579
  • 20
  • 231
  • 279
  • Thanks for the reply, I have some 32 bit openwrt devices. In that case, it doesn't give any result to `ifHCInOctets` or `ifHCOutOctets` instead `ifInOctets` and `ifOutOctets` respectively. And the result it gives in bits or bytes? I am confused. Also maximum up to which number this will increase? if the number goes upto maximum which it can fit, then what will happen? – Muneer Apr 01 '15 at 05:51
  • 1
    @Muneer well, when it hits 2³² bytes (*octet* = 8-bit byte), it should roll over. You'll have to poll frequently (possibly very frequently) to get a good count, depending on the bitrate. 32-bit rollover is slightly over 5 minutes at 100mbps, around 30s at 1gbps. You need to poll several times faster than that, to distinguish between rollover and reset-to-0 (e.g., power cycle). https://dev.openwrt.org/ticket/13597 has something about adding 64-bit counter support. There are, BTW, existing open source tools which handle this stuff, including at least Cacti and MRTG. – derobert Apr 01 '15 at 07:17