Monitoring bandwidth usage - writing a simple monitor - Networking

This is a discussion on Monitoring bandwidth usage - writing a simple monitor - Networking ; 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 ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Monitoring bandwidth usage - writing a simple monitor

  1. Monitoring bandwidth usage - writing a simple monitor

    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!


  2. Re: Monitoring bandwidth usage - writing a simple monitor

    On 15 Dec 2007 19:23:46 GMT, 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.
    >
    > 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


  3. Re: Monitoring bandwidth usage - writing a simple monitor

    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_

  4. Re: Monitoring bandwidth usage - writing a simple monitor

    On Dec 15, 11:23 pm, 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.
    >
    > 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!

  5. Re: Monitoring bandwidth usage - writing a simple monitor

    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 to Thread