With a lot of help from my friends I wrote a bash script that displays
the number of kilobytes being uploaded & downloaded every second via my
eth0 internet connection.
The ouput looks like:
$ monitor
10.8 k/s 2.3 k/s
22.3 k/s 1.3 k/s
12.1 k/s 3.1 k/s
...
The logic of the script goes something like this:
init:
invoke netstat to retrieve initial packet counts
do forever:
invoke netstat to retrieve next packet counts
compute kilobyte delta = packet delta * MTU / 1024
display results
This works fine and displays plausible results, but they seem to differ
somewhat (+20-30%) from an earlier version that collected byte counts
from the kernel's /proc/net/dev pseudo-file.
I understand that the above approach is not entirely correct since I
wait one second (how accurate is that on a multi-processing OS?) but
also, some correction factor would need to be applied to account for
the elapsed time that is necessary for the code itself to execute ..
the fact this is a bash script at this point probably doesn't help.
I also realize that there are probably CLI tools that already do
something similar. I definitely would be curious if any one recommended
something that might display this information and I would take a look
as to how their authors went about doing this.
Naturally, I don't need anything highly accurate .. this is both an
exercise to try and understand these aspects better .. and something
that will display two counters at the bottom of my screen so I have some
idea of what is going on with the system.
Thanks!