Linux – How to Get Single Bandwidth Usage Sample

bandwidthlinuxmonitoringnetworkingscript

What I want to do is to write a script that gathers some information (like cpu temperature and bandwidth usage) and logs it into a file.

I can't figure out how to get a single sample of the current used bandwidth: I've found that there's plenty of tools to get this information from command line, but the majority of them are curses based, so I can't take their output to put it into a file. Among these I've found bmon, that has a nice ascii output. The problem is that this output is updated constantly, while what I want is a single "sample" per program call.

Is there a way to get this done with bmon or someone knows another program to accomplish this task?

Best Answer

Lucky for you sysstat already exists and already does what you're trying to make.

1 . Install your distro's sysstat package then add the following to /etc/crontab:

*/5 * * * * root /usr/lib/sysstat/sa1 &
5 19 * * * root /usr/lib/sysstat/sa2 -A &

2 . Wait 10 minutes. Use this time to read the sar man page.

3 . Enjoy using sar.

Related Question