• You are not registered on MyBroadband, which means you miss out on great benefits. To join our community is very easy, and completely free. Register now.
  • New Two-Day Giveaway - Enter Here

Linux HOWTO (Stats/Usage Setup)

Tazz_Tux

Linux Guru
Joined
Jan 28, 2005
Messages
622
#1
Hello Everyone,

I use this "quick-and-dirty" script to show usage under Linux. I am sure it can be made better, but it was a 2 min job. I have this in my cron jobs that calcs usage for the day, then rotates the log.

I have added a line to my /etc/syslog.conf:

Code:
*.*                /var/log/all.log
Restart syslog after that. I also have debugging on in /etc/ppp/options:

Code:
debug
kdebug 4
calc_usage.sh
Code:
#!/bin/bash

logfile="/var/log/all.log"
tempfile="/tmp/logs"
datafile="/tests/data_usage"

cat $logfile | grep pppd | grep Sent > $tempfile
cat $datafile >> $tempfile

cat $tempfile | grep pppd | grep Sent | sort | uniq > $datafile

cat $datafile | gawk -F\  '{print $7"+"}' | xargs > /tmp/sent
echo "0" >> /tmp/sent
echo -n "Sent Total : " && cat /tmp/sent | xargs | bc
cat $datafile | gawk -F\  '{print $10"+"}' | xargs > /tmp/recv
echo "0" >> /tmp/recv
echo -n "Recv Total : " && cat /tmp/recv | xargs | bc
rm -rf /tmp/sent
rm -rf /tmp/recv
rm -rf $tempfile
Demo:

localhost tests # ./calc_usage.sh
Sent Total : 9891729
Recv Total : 10027875

Enjoy !!!

Please do not post question in this thread - rather post them in the sub forum
 
Last edited:

Paul_S

Expert Member
Joined
Jun 4, 2006
Messages
4,440
#2
There's an easier way if the only ppp device used on your system is the 3G one.
Install and use vnstat.

It will give you a breakdown of usage per hour, day, week or month.
It can also show you the throughput.

Usage :
Code:
[color=blue]user@kubuntu:~$ vnstat -q
Database updated: Sun Jan 13 06:10:01 2008

        ppp0

           received:         381.73 MB (87.2%)
        transmitted:          56.04 MB (12.8%)
              total:         437.78 MB

                        rx     |     tx     |  total
        -----------------------+------------+-----------
        yesterday     83.85 MB |   13.77 MB |   97.62 MB
            today      3.13 MB |    1.07 MB |    4.21 MB
        -----------------------+------------+-----------
        estimated        11 MB |       3 MB |      14 M[/color]
Usage per month :
Code:
[color=blue]user@kubuntu:~$ vnstat -q -m

        ppp0

           month        rx      |       tx      |    total
        ------------------------+---------------+---------------
          Dec '07    205.96 MB  |     28.81 MB  |    234.77 MB
          Jan '08    176.13 MB  |     27.35 MB  |    203.49 MB
        ------------------------+---------------+---------------
        estimated       445 MB  |        68 MB  |       513 MB[/color]
Usage per day :
Code:
[color=blue]user@kubuntu:~$ vnstat -q -d

        ppp0

            day         rx      |     tx      |  total
        ------------------------+-------------+--------------
           15.12.     22.65 MB  |    3.20 MB  |   25.85 MB
           17.12.      3.37 MB  |    0.90 MB  |    4.28 MB
           18.12.      1.50 MB  |    0.11 MB  |    1.62 MB
           19.12.      4.34 MB  |    0.54 MB  |    4.88 MB
           21.12.     28.24 MB  |    2.63 MB  |   30.88 MB
           22.12.     26.76 MB  |    3.96 MB  |   30.72 MB
           24.12.     29.51 MB  |    2.82 MB  |   32.33 MB
           25.12.      1.37 MB  |    0.11 MB  |    1.48 MB
           26.12.     35.97 MB  |    4.35 MB  |   40.32 MB
           27.12.      3.82 MB  |    0.61 MB  |    4.44 MB
           28.12.     14.20 MB  |    1.92 MB  |   16.12 MB
           29.12.     15.84 MB  |    4.43 MB  |   20.28 MB
           30.12.      7.81 MB  |    1.21 MB  |    9.02 MB
           31.12.     10.52 MB  |    1.95 MB  |   12.48 MB
           01.01.      7.64 MB  |    1.56 MB  |    9.20 MB
           03.01.      4.08 MB  |    1.27 MB  |    5.36 MB
           04.01.      1.09 MB  |    0.28 MB  |    1.37 MB
           05.01.      6.22 MB  |    1.69 MB  |    7.92 MB
           07.01.      8.67 MB  |    1.26 MB  |    9.94 MB
           08.01.     16.28 MB  |    1.62 MB  |   17.90 MB
           09.01.      6.27 MB  |    0.60 MB  |    6.87 MB
           10.01.     11.64 MB  |    1.07 MB  |   12.72 MB
           11.01.     26.84 MB  |    2.98 MB  |   29.83 MB
           12.01.     83.85 MB  |   13.77 MB  |   97.62 MB
           13.01.      3.48 MB  |    1.18 MB  |    4.67 MB
        ------------------------+-------------+--------------
         estimated       11 MB  |       3 MB  |      14 MB[/color]
Then there is also a PHP frontend for it.



http://humdi.net/vnstat/
 

Veroland

Executive Member
Joined
Aug 24, 2005
Messages
5,580
#3
EDIT: Thanks Paul_S, your post helped me a lot for a easy monitoring tool

There's an easier way if the only ppp device used on your system is the 3G one.
Install and use vnstat.

It will give you a breakdown of usage per hour, day, week or month.
It can also show you the throughput.

Usage :
Code:
[color=blue]user@kubuntu:~$ vnstat -q
Database updated: Sun Jan 13 06:10:01 2008

        ppp0

           received:         381.73 MB (87.2%)
        transmitted:          56.04 MB (12.8%)
              total:         437.78 MB

                        rx     |     tx     |  total
        -----------------------+------------+-----------
        yesterday     83.85 MB |   13.77 MB |   97.62 MB
            today      3.13 MB |    1.07 MB |    4.21 MB
        -----------------------+------------+-----------
        estimated        11 MB |       3 MB |      14 M[/color]
Usage per month :
Code:
[color=blue]user@kubuntu:~$ vnstat -q -m

        ppp0

           month        rx      |       tx      |    total
        ------------------------+---------------+---------------
          Dec '07    205.96 MB  |     28.81 MB  |    234.77 MB
          Jan '08    176.13 MB  |     27.35 MB  |    203.49 MB
        ------------------------+---------------+---------------
        estimated       445 MB  |        68 MB  |       513 MB[/color]
Usage per day :
Code:
[color=blue]user@kubuntu:~$ vnstat -q -d

        ppp0

            day         rx      |     tx      |  total
        ------------------------+-------------+--------------
           15.12.     22.65 MB  |    3.20 MB  |   25.85 MB
           17.12.      3.37 MB  |    0.90 MB  |    4.28 MB
           18.12.      1.50 MB  |    0.11 MB  |    1.62 MB
           19.12.      4.34 MB  |    0.54 MB  |    4.88 MB
           21.12.     28.24 MB  |    2.63 MB  |   30.88 MB
           22.12.     26.76 MB  |    3.96 MB  |   30.72 MB
           24.12.     29.51 MB  |    2.82 MB  |   32.33 MB
           25.12.      1.37 MB  |    0.11 MB  |    1.48 MB
           26.12.     35.97 MB  |    4.35 MB  |   40.32 MB
           27.12.      3.82 MB  |    0.61 MB  |    4.44 MB
           28.12.     14.20 MB  |    1.92 MB  |   16.12 MB
           29.12.     15.84 MB  |    4.43 MB  |   20.28 MB
           30.12.      7.81 MB  |    1.21 MB  |    9.02 MB
           31.12.     10.52 MB  |    1.95 MB  |   12.48 MB
           01.01.      7.64 MB  |    1.56 MB  |    9.20 MB
           03.01.      4.08 MB  |    1.27 MB  |    5.36 MB
           04.01.      1.09 MB  |    0.28 MB  |    1.37 MB
           05.01.      6.22 MB  |    1.69 MB  |    7.92 MB
           07.01.      8.67 MB  |    1.26 MB  |    9.94 MB
           08.01.     16.28 MB  |    1.62 MB  |   17.90 MB
           09.01.      6.27 MB  |    0.60 MB  |    6.87 MB
           10.01.     11.64 MB  |    1.07 MB  |   12.72 MB
           11.01.     26.84 MB  |    2.98 MB  |   29.83 MB
           12.01.     83.85 MB  |   13.77 MB  |   97.62 MB
           13.01.      3.48 MB  |    1.18 MB  |    4.67 MB
        ------------------------+-------------+--------------
         estimated       11 MB  |       3 MB  |      14 MB[/color]
Then there is also a PHP frontend for it.



http://humdi.net/vnstat/
Just to add a little, if you have more than one ppp device like I do you need to specify the device.

My 3G card is installed on ttyUSB0 but vnstat does not recognise that as a device but instead it detetcs it on ppp0.

So to create a database just run
Code:
#vnstat -u -i ppp0
Then to query
Code:
#vnstat -q -i ppp0
This way you can set up each of your devices.
 
Last edited:

morkhans

A MyBroadband
Super Moderator
Joined
Jun 22, 2007
Messages
10,487
#4
This really is a fantastic tool. I got it up and running on a FreeBSD box at work in no time. The PHP frontend is really nice.
 
Top