Networking Forums

Networking Forums > Computer Networking > Linux Networking > Monitoring bandwidth usage - writing a simple monitor

Reply
Thread Tools Display Modes

Monitoring bandwidth usage - writing a simple monitor

 
 
cga2000
Guest
Posts: n/a

 
      12-15-2007, 06:23 PM
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!

 
Reply With Quote
 
 
 
 
cga2000
Guest
Posts: n/a

 
      12-16-2007, 02:55 AM
On 15 Dec 2007 19:23:46 GMT, cga2000 <(E-Mail Removed)> wrote:
> 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:
>
> sleep 1
> 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!
>


fat fingers .. lost the " sleep 1" above .. sorry

 
Reply With Quote
 
artix
Guest
Posts: n/a

 
      12-29-2007, 08:25 AM
cga2000 wrote:
> 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.


I use this script for that:

http://www.comp.eonworks.com/scripts...-20040720.html

works well.
--
artix
http://www.abstractart.ws _Abstract Art Directory_
 
Reply With Quote
 
Suren
Guest
Posts: n/a

 
      12-30-2007, 08:48 AM
On Dec 15, 11:23 pm, cga2000 <cga2...@optonline.net> wrote:
> 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!


Hi
Doing this "kilobyte delta = packet delta * MTU / 1024" You assume
that all the packets are MTU bytes long, which is not true.
The first approach of reading byte counters was better. You should use
it.
And also take a look at http://ibmonitor.sourceforge.net/

Cheers!
 
Reply With Quote
 
goarilla
Guest
Posts: n/a

 
      01-01-2008, 08:18 PM
artix schreef:
> cga2000 wrote:
>> 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.

>
> I use this script for that:
>
> http://www.comp.eonworks.com/scripts...-20040720.html
>
> works well.

i use gkrellm for that
iirc iptraf can do it as well albeit in a very verbose fashion
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Transparent Internet Bandwidth / Usage monitoring Sam Linux Networking 4 04-27-2008 09:07 PM
How to monitor bandwidth usage between two computers Martin X. Windows Networking 1 12-21-2007 12:30 AM
Monitoring Web Usage DSt Linux Networking 3 06-23-2006 03:01 PM
Monitoring share usage. Purtech Windows Networking 4 05-17-2006 04:52 PM
Simple daemon to log bandwidth usage per port/host? Jonathan A. Linux Networking 2 10-17-2003 08:37 PM



1 2 3 4 5 6 7 8 9 10 11