I found this script at https://github.com/Cosmologist/collectd-network-bandwidth-usage.
<Plugin exec>
Exec user "/tmp/exec-network-bandwidth-usage.sh" "eth0"
</Plugin>
It runs a bash script that checks /sys/class/net/eth0/statistics/rx_bytes and tx_bytes.
#!/bin/bash
HOSTNAME="${COLLECTD_HOSTNAME:-`hostname -f`}"
INTERVAL="${COLLECTD_INTERVAL:-60}"
while sleep "$INTERVAL"; do
RX=`cat /sys/class/net/$1/statistics/rx_bytes`
TX=`cat /sys/class/net/$1/statistics/tx_bytes`
echo "PUTVAL $HOSTNAME/network-bandwidth-usage/if_octets interval=$INTERVAL N:$RX:$TX"
done
My goal is to see how much MB's of traffic was transfered in a timespan. How reliable is using the data from /sys/class/net/eth0/statistics/rx_bytes like this to find out how much traffic our entire server farm is producing?
I´ve installed in a lot of my linux servers to monitor my traffic interface the vnstat command. It is very easy to install and you get with this great deal of information. https://www.howtoforge.com/tutorial/vnstat-network-monitoring-ubuntu/
I guess /sys/class/net/eth0/statistics are reliable but will have to be stored in a monitoring app to extract then useful information... With vnstat installed in our system you have all this information when you need it in the system itself.
I hope it can be useful
Kind regards