On 05/13/2014 09:50 AM, Lonnie Olson wrote:
On Tue, May 13, 2014 at 1:07 AM, Dan Egli <[email protected]> wrote:
I was goofing around and decided I'd write a quick script that calls
ifconfig so as to determine how much bandwidth is being used (up and down
stream) on average. I wound up with something that I think would work, but
I'm wondering if I can't do it better.
Not a bad idea, but better than forking out to ifconfig, might be to
read from files in /proc.
Example:
awk '/^IpExt: [0-9]/{print $8 " " $9}' /proc/net/netstat
or
awk '/^IFACE/{print $2 " " $10}' /proc/net/dev
etc.


this data is also available in sysfs. in /sys/class/net/$IFACE/statistics there should be rx_bytes and tx_bytes which only contain the number matching those values. just read the contents of those files and no need to awk or even fork a process. yet another reason to love sysfs.

mike

/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/

Reply via email to