LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Need software to monitor network usage (https://www.linuxquestions.org/questions/linux-networking-3/need-software-to-monitor-network-usage-449534/)

cdhgee 05-29-2006 04:23 AM

Need software to monitor network usage
 
I use a broadband ADSL service that has a monthly usage cap. As my Linux machine generates most of the traffic, I would like to use it to monitor my usage.

Can anyone suggest some software that would be able to monitor my network usage?

Regards
David Gee

tredegar 05-29-2006 06:28 AM

The newer ADSL modems hava a web interface that you can use to configure the modem. If you have one of these, somewhere in all those pages is a running tally of bytes uploaded/dowwnloaded since the last reset. Usually you can also reset the counters to zero (eg at the beginning of your accounting period). For my zoom X5, I click on Advanced Settings, then ATM Status, to see a whole load of statistics.
This has the advantage that it monitors your connection, rather than one specific machine.

HTH

cdhgee 05-29-2006 05:27 PM

Hadn't thought of that. The router does have a stats page, but it only shows packet counts, not byte counts, and as packets vary in size that's not overly useful, so I think it may have to be some software after all.

cmsps 07-30-2006 10:12 AM

Simple solution
 
I have this in /etc/ppp/ip-down.local:

Code:

#!/bin/sh
#
# ip-down.local - called to add stats to /var/log/net
#
# Sat Oct  8 16:12:58 BST 2005
#

echo `date; /sbin/ifconfig $1 |
        sed -n '7s/([^)]*)//gp'` >> /var/log/net

It takes the RX/TX info from line seven of the ifconfig command for your ppp device and puts it into a logging file.

I use this command to display the totals:

Code:

#!/bin/sh
#
# netStats RE - display stats for RE in /var/log/net
#
# Sat Dec 17 16:03:48 GMT 2005
#


# usage - display usage message
#
usage () {
  echo "Usage: $NAME [ RE ]"
  exit 1
}


NAME=`basename $0`
if [ $# -lt 2 ]
then    re=$1
else    usage
fi
awk "/$re/"'{ rx += substr( $8, 7)
              tx += substr( $10, 7)
            }
    END    { rxm = rx / (1024 * 1024)
              rxg = rxm / 1024
              txm = tx / (1024 * 1024)
              txg = txm / 1024
              printf "RX: %0.1f Mb (%0.1f Gb)  ", rxm, rxg
              printf "TX: %0.1f Mb (%0.1f Gb)\n", txm, txg
            }
' /var/log/net

For example:

Code:

    $ netStats Jun
    RX: 4941.2 Mb (4.8 Gb)  TX: 489.1 Mb (0.5 Gb)
    $

Hope this helps,

Peter

tredegar 07-30-2006 11:54 AM

Neat script Peter, and rather good for a "First post"! I am sure others will find it useful.
Welcome to LQ!

cmsps 01-12-2007 11:25 AM

Post Firestarter script
 
After I installed Firestarter the ip-down.local script stopped working, probably because firestarter destroys ppp0 when it closes down.

Here is the latest version:
Code:

#!/bin/sh
#
# ip-down.local - called to add stats to /var/log/net
#
# Fri Dec 29 20:19:37 GMT 2006
#

echo `date` RX bytes:$BYTES_RCVD TX bytes:$BYTES_SENT >> /var/log/net



All times are GMT -5. The time now is 05:23 AM.