Join us now. It is free, and it takes less than 1 minute to register.
Register now
Subscribe to our daily newsletter. It is free, and it comes with many benefits.


+ Reply to Thread
Results 1 to 8 of 8

Thread: Linux HOWTO (Stats/Usage Setup)

  1. #1
    Linux Guru
    Join Date
    Jan 2005
    Location
    New Germany, Durban
    Posts
    622
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Linux HOWTO (Stats/Usage Setup)

    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 by Tazz_Tux; 03-03-2007 at 07:43 AM.

  2. #2
    Grandmaster
    Join Date
    Jun 2006
    Posts
    4,440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    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:
    [email protected]:~$ 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
    Usage per month :
    Code:
    [email protected]:~$ 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
    Usage per day :
    Code:
    [email protected]:~$ 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
    Then there is also a PHP frontend for it.



    http://humdi.net/vnstat/

  3. #3
    Super Grandmaster
    Join Date
    Aug 2005
    Location
    South Crest, Alberton
    Posts
    5,578
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    EDIT: Thanks Paul_S, your post helped me a lot for a easy monitoring tool

    Quote Originally Posted by Paul_S View Post
    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:
    [email protected]:~$ 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
    Usage per month :
    Code:
    [email protected]:~$ 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
    Usage per day :
    Code:
    [email protected]:~$ 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
    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 by Veroland; 30-01-2009 at 08:21 AM.
    Everyone's first vi session. ^C^C^X^X^X^XquitqQ!qdammit[esc]qwertyuiopasdfghjkl;:xwhat

  4. #4
    moderator morkhans's Avatar
    Join Date
    Jun 2007
    Location
    Cape Town
    Posts
    10,395
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default

    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.
    53.91% of South Africans voted in favour of the Nkandla compound and SABC censorship.

  5. #5
    moderator morkhans's Avatar
    Join Date
    Jun 2007
    Location
    Cape Town
    Posts
    10,395
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default

    Ginggs recently put me onto USSD codes and command line stuff. I found this perl script which you can hack to send USSD queries to check balances. https://github.com/JochenHoch2/gsm-u...master/INSTALL
    53.91% of South Africans voted in favour of the Nkandla compound and SABC censorship.

  6. #6
    Super Grandwizard ginggs's Avatar
    Join Date
    Jun 2006
    Location
    Kapkaupunki
    Posts
    10,991
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)

    Default

    Quote Originally Posted by morkhans View Post
    Ginggs recently put me onto USSD codes and command line stuff. I found this perl script which you can hack to send USSD queries to check balances. https://github.com/JochenHoch2/gsm-u...master/INSTALL
    We have a thread for that.

  7. #7
    moderator morkhans's Avatar
    Join Date
    Jun 2007
    Location
    Cape Town
    Posts
    10,395
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default

    Quote Originally Posted by ginggs View Post
    We have a thread for that.
    Cool!
    53.91% of South Africans voted in favour of the Nkandla compound and SABC censorship.

  8. #8
    Super Grandmaster The_Unbeliever's Avatar
    Join Date
    Apr 2005
    Location
    Nkaaaaandla
    Posts
    103,205
    Blog Entries
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I love it when a plan comes together...
    Is the 10 Commandments for Christians?

    Saturday is the Seventh day, Sunday is the first day.

+ Reply to Thread

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •