You are not logged in.
If anyone has a mobile broadband connection, they probably have a limit. A great tool to measure your daily/weekly/monthly usage is vnstat.
You only need to install the one package.
sudo apt-get install vnstatDuring the install it will try to start the daemon, but it will fail. First you have to tell it what interfaces to monitor. Execute something like the following in your terminal, changing the interface to match your mobile connection.
sudo vnstat -u -i ppp0If you want the totals to follow your billing month and not the actual month you will need to edit /etc/vnstat.conf. Change MonthRotate to whenever your billing date is.
# on which day should months change
MonthRotate 10Now start the daemon:
sudo service vnstat startNow to check how much bandwidth you have used you can simply type vnstat into your terminal. benj1 has wrote a python script to make it easy to use this info with conky. Thanks benj1! To use it with conky add something like this to your conky config.
For total usage:
Total:${alignr}${execi 300 vnstat-conky-script.py}For sent monthly total:
Sent:${alignr}${execi 300 vnstat-conky-script.py -s}For recieved monthly total:
Recieved:${alignr}${execi 300 vnstat-conky-script.py -r}Last edited by hardran3 (2011-03-18 01:10:57)
Offline
it's quite easy to integrate with your conky simple put this into your .conkyrc
${exec vnstat}registered Linux user: #533379
registered #! user: #6769
Whenever someone calls me a computer 'nerd' or a 'Unix-based-system'
all I can think is: You just wait. In a couple of years. I'll be your IT. Then where will you be!
Offline
EDIT: on 32bit systems you need to update vnstat before it hits 4gb. From man vnstat:
RESTRICTIONS
Updates needs to be executed at least as often as it is possible for
the interface to generate enough traffic to wrap the kernel interface
traffic counter.You can change the update interval by making a cron job:
gksu gedit /etc/cron.d/vnstatwith this in it:
# 0-55/5 * * * * root if [ -x /usr/bin/vnstat ] && [ `ls /var/lib/vnstat/ | wc -l` -ge 1 ]; then /usr/bin/vnstat -u; fi
0-59 * * * * root if [ -x /usr/bin/vnstat ] && [ `ls /var/lib/vnstat/ | wc -l` -ge 1 ]; then /usr/bin/vnstat -u; fiThe #'d line updates vnstat every 5 mins the other every 1min
To display monthly totals in conky:
Rx (Month):$alignr${execi 300 vnstat -i XXXX -m | grep "`date +"%b '%y"`" | awk '{print $3 $4}'}
Tx (Month):$alignr${execi 300 vnstat -i XXXX -m | grep "`date +"%b '%y"`" | awk '{print $6 $7}'}replacing XXXX with the interface you are using (eg wlan0)
Last edited by Hinterland (2011-03-16 03:36:26)
Offline
EDIT: on 32bit systems you need to update vnstat before it hits 4gb. From man vnstat:
RESTRICTIONS Updates needs to be executed at least as often as it is possible for the interface to generate enough traffic to wrap the kernel interface traffic counter.You can change the update interval by making a cron job...
The cron job is not necessary as we are using vnstatd. It also fixes the 4GB wrap on 32 bit systems. From the vnstatd man page:
The purpose of vnstatd is to provide a more flexible way for updating vnstat(1) databases than what using cron for updating can provide. The daemon makes possible updating databases more often but at the same time requires less disk access since data can be cached and written only later to disk at a user configurable interval. It is also able to track how interfaces come and go without the need of additional scripts that are required with cron based updates.
Thanks for the conky lines 
Last edited by hardran3 (2011-03-16 05:45:08)
Offline
Oops sorry! 
Thanks for this, binned the cron and swapped to vnstatd 
Last edited by Hinterland (2011-03-16 07:53:16)
Offline
I wrote this script for use with conky.
#!/usr/bin/env python
#
# vnstat-conky-script.py
#
# get monthly download totals from vnstat, for display in conky
#
from subprocess import Popen,PIPE
import sys
def sizeformat(size):
suffix = ['B','KB','MB','GB','TB']
count = 0
while size >= 1024 and count < len(suffix)-1:
count += 1
size = size/1024
return "%.2f%s" % (size, suffix[count])
# get output
output = Popen(["vnstat", "--dumpdb"], stdout= PIPE).communicate()[0]
# get the correct line (first to start with m)
line = (i for i in output.split('\n') if i.startswith('m') ).next()
#split line out into constituent parts
mon,mon_num,nixtime,rec_mb,tran_mb,rec_kb,tran_kb,inuse=line.split(';')
if len(sys.argv) == 1: #no args return total
print sizeformat(((float(rec_mb)*1024*1024)+(float(rec_kb)*1024))
+(float(tran_mb)*1024*1024)+(float(tran_kb)*1024))
elif sys.argv[1] == '-r': #received
print sizeformat((float(rec_mb)*1024*1024)+(float(rec_kb)*1024))
elif sys.argv[1] == '-s':#sent
print sizeformat((float(tran_mb)*1024*1024)+(float(tran_kb)*1024))
else:
print "'%s' flag not recognised, use -r flag (received), -s flag (sent) or no flag (total)" % sys.argv[1]When called with the -r flag it returns the received monthly total, when called with the -s flag it returns the sent monthly total and when called without args it returns the overall sent/received monthly total.
All nicely formatted with mb/gb/tb?!
(its futureproof I suppose).
Last edited by benj1 (2011-03-17 13:49:15)
- - - - - - - - Wiki Pages - - - - - - -
#! install guide *autostart programs, modify the menu & keybindings
configuring Conky *installing scripts
Offline
I wrote this script for use with conky.
Thanks! It works great for the -r and -s options, but when I run it with no arguments I get an error.
~/bin$ vnstat-conky-script.py
Traceback (most recent call last):
File "/home/ryan/bin/vnstat-conky-script.py", line 24, in <module>
if sys.argv[1] == '-r': #received
IndexError: list index out of rangeI can muddle my way through bash, but have no idea about python.
Offline
benj1 wrote:I wrote this script for use with conky.
Thanks! It works great for the -r and -s options, but when I run it with no arguments I get an error.
~/bin$ vnstat-conky-script.py Traceback (most recent call last): File "/home/ryan/bin/vnstat-conky-script.py", line 24, in <module> if sys.argv[1] == '-r': #received IndexError: list index out of rangeI can muddle my way through bash, but have no idea about python.
youre correct, looking at my conkyrc im using a -t flag, but any argument that isn't -s or -r will do, ill rewrite it to be a bit more obvious.
EDIT
ive updated my previous script so it should work as advertised, no flag returns the overall total, flags that aren't -s or -r return an error.
Last edited by benj1 (2011-03-17 13:51:42)
- - - - - - - - Wiki Pages - - - - - - -
#! install guide *autostart programs, modify the menu & keybindings
configuring Conky *installing scripts
Offline
It's working!!! Thanks a lot guys! 
Now if I could just stop conky from disappearing from my desktop all the time... 
Offline
Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.