I would like to validate a certain thought with you guys. Assuming that:
- The device whose bandwidth I am measuring is an internal, Linux-based, router.
- If a NIC is configured to 100mbps, the network is at least 100mbps (that is, the NIC's speed setting it what is limiting the bandwidth, not the network, its latency, etc.)
- Elements such as CPU have no impact on bandwidth.
Would it be correct to:
- Run ifconfig every 10 seconds
- Calculate the bytes TX+RX per second based on the ifconfig's results
- Multiply the bytes number by 8 (let's say this is X)
- Get the NIC speed settings (10mbps, 100mbps, 1000mbps, this is Y)
- Calculate the bandwidth percent usage as: X / (Y*1024*1024)
Is this correct? How does duplicity impact this calculation?
Theoretically this is correct. However, using ifconfig to retrieve the relevant figures is a very roundabout way to achieve this. You'd be much better off using SNMP. All interfaces have entries in the standard SNMP MIBs, which describe them and also their current connection speed, plus all sorts of relevant counters.
SNMP is available through standard packages in all linux distros I know off, and you can either use tools such as snmpwalk or snmpget (if you just want to retrieve the data) or MRTG or cacti (if you want to graph the data). Especially cacti will allow to apply formulae (formulas?) to your data, and it should be easy to get a percentage graph out of that.