View Full Version : Linux HOWTO (Stats/Usage Setup)
Tazz_Tux
17-02-2007, 07:15 AM
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:
*.* /var/log/all.log
Restart syslog after that. I also have debugging on in /etc/ppp/options:
debug
kdebug 4
calc_usage.sh
#!/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 (http://mybroadband.co.za/vb/forumdisplay.php?f=151)
Paul_S
13-01-2008, 06:27 AM
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 :
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
Usage per month :
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
Usage per day :
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
Then there is also a PHP frontend for it.
http://www.sqweek.com/sqweek/files/scrot1.png
http://www.sqweek.com/sqweek/files/scrot2.png
http://humdi.net/vnstat/
Veroland
30-01-2009, 08:18 AM
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 :
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
Usage per month :
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
Usage per day :
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
Then there is also a PHP frontend for it.
http://www.sqweek.com/sqweek/files/scrot1.png
http://www.sqweek.com/sqweek/files/scrot2.png
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
#vnstat -u -i ppp0
Then to query
#vnstat -q -i ppp0
This way you can set up each of your devices.
morkhans
10-02-2009, 07:40 AM
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.
morkhans
10-11-2010, 09:31 PM
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-ussd/blob/master/INSTALL
ginggs
12-11-2010, 02:00 PM
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-ussd/blob/master/INSTALL
We have a thread (http://mybroadband.co.za/vb/showthread.php/271559) for that.
morkhans
12-11-2010, 02:08 PM
We have a thread (http://mybroadband.co.za/vb/showthread.php/271559) for that.
Cool!
The_Librarian
04-12-2010, 09:42 AM
I love it when a plan comes together...