skip to main | skip to sidebar
Showing posts with label networking. Show all posts
Showing posts with label networking. Show all posts

Saturday, October 10, 2009

Keep track of your network usage using vnstat

Since I started using my mobile connection to connect to Internet (now and then), I felt the need to keep track of my network usage (since I only have 500mb a month, and my provider doesn't seem to provide the usage on a website). And of course, I'm talking Linux OS ;-)

I stumbled upon this nice software, vnstat, http://humdi.net/vnstat, which really suits my needs.

Unfortunately, the version that comes with Ubuntu is quite old, so I was suggested in the forum, to download and compile from sources the latest version from the website.

After unpackaged the tarbal, it's just a matter of running make install (as a superuser)

sudo make install
Installing vnStat...
Installing config to /etc/vnstat.conf
install -d -m 755 /usr/bin /usr/sbin /usr/share/man/man1 /usr/share/man/man5 /var/lib/vnstat
install -s -m 755 src/vnstat /usr/bin
install -s -m 755 src/vnstatd /usr/sbin
install -m 644 man/vnstat.1 /usr/share/man/man1
install -m 644 man/vnstatd.1 /usr/share/man/man1
install -m 644 man/vnstat.conf.5 /usr/share/man/man5
Then, the first time, you need to create the database; since I'm interested in my ppp0 mobile connection, I did
sudo vnstat --force -u -i ppp0
Before starting, I prefered to tweak the configuration a bit, so I created $HOME/.vnstatrc and I added this option
# interface specific limits
# example 8Mbit limit for eth0 (remove # to activate):
#MaxBWeth0 8
MaxBWppp0 8
This seemed to help getting rid of those annoying 4gb spikes. (On a side note, I often use the application that came with my Internet Huawei card, which often, very often, suffer from those 4gb spikes which definitely spoil the statistics of network usage, that's why I had to find a better solution to keep track of that.)

Now you can setup the vnstat daemon so that it starts automatically when the computer starts
sudo cp examples/init.d/ubuntu/vnstat /etc/init.d/
sudo chmod 755 /etc/init.d/vnstat
sudo update-rc.d vnstat defaults
And if you want to start it right now
sudo /etc/init.d/vnstat start
Every 5 minutes the daemon updates the database with the statistics (of course you can configure many things, see the vnstat documentation).

You can see the current statistics
bettini@bettini-laptop:~$ vnstat
Database updated: Sat Oct 10 15:37:54 2009

ppp0 since 04.09.09

rx: 292.90 MiB tx: 104.48 MiB total: 397.38 MiB

monthly
rx | tx | total | avg. rate
------------------------+-------------+-------------+---------------
Sep '09 243.74 MiB | 88.89 MiB | 332.62 MiB | 1.05 kbit/s
Oct '09 49.16 MiB | 15.59 MiB | 64.76 MiB | 0.64 kbit/s
------------------------+-------------+-------------+---------------
estimated 157 MiB | 48 MiB | 205 MiB |

daily
rx | tx | total | avg. rate
------------------------+-------------+-------------+---------------
yesterday 329 KiB | 172 KiB | 501 KiB | 0.05 kbit/s
today 7.91 MiB | 2.25 MiB | 10.16 MiB | 1.48 kbit/s
------------------------+-------------+-------------+---------------
estimated 10 MiB | 3 MiB | 13 MiB |

The daily statistics
bettini@bettini-laptop:~$ vnstat -d

ppp0 / daily

day rx | tx | total | avg. rate
------------------------+-------------+-------------+---------------
04.09. 8.96 MiB | 6.99 MiB | 15.94 MiB | 1.51 kbit/s
05.09. 12.05 MiB | 4.37 MiB | 16.42 MiB | 1.56 kbit/s
06.09. 9.21 MiB | 4.14 MiB | 13.35 MiB | 1.27 kbit/s
08.09. 25.17 MiB | 9.68 MiB | 34.86 MiB | 3.30 kbit/s
09.09. 6.64 MiB | 2.74 MiB | 9.38 MiB | 0.89 kbit/s
10.09. 22.53 MiB | 7.88 MiB | 30.41 MiB | 2.88 kbit/s
12.09. 10.58 MiB | 4.64 MiB | 15.22 MiB | 1.44 kbit/s
13.09. 5.13 MiB | 2.07 MiB | 7.21 MiB | 0.68 kbit/s
14.09. 7.67 MiB | 2.18 MiB | 9.86 MiB | 0.93 kbit/s
18.09. 12.54 MiB | 2.31 MiB | 14.85 MiB | 1.41 kbit/s
19.09. 16.28 MiB | 5.14 MiB | 21.42 MiB | 2.03 kbit/s
20.09. 4.76 MiB | 1.47 MiB | 6.24 MiB | 0.59 kbit/s
22.09. 11.99 MiB | 4.29 MiB | 16.27 MiB | 1.54 kbit/s
23.09. 17.75 MiB | 8.66 MiB | 26.41 MiB | 2.50 kbit/s
24.09. 8.80 MiB | 2.94 MiB | 11.74 MiB | 1.11 kbit/s
26.09. 15.72 MiB | 4.99 MiB | 20.71 MiB | 1.96 kbit/s
27.09. 383 KiB | 108 KiB | 491 KiB | 0.05 kbit/s
29.09. 23.36 MiB | 6.18 MiB | 29.55 MiB | 2.80 kbit/s
30.09. 24.23 MiB | 8.09 MiB | 32.32 MiB | 3.06 kbit/s
01.10. 9.90 MiB | 5.62 MiB | 15.52 MiB | 1.47 kbit/s
04.10. 22.22 MiB | 5.15 MiB | 27.37 MiB | 2.60 kbit/s
05.10. 8.81 MiB | 2.40 MiB | 11.21 MiB | 1.06 kbit/s
09.10. 329 KiB | 172 KiB | 501 KiB | 0.05 kbit/s
10.10. 7.91 MiB | 2.25 MiB | 10.16 MiB | 1.48 kbit/s
------------------------+-------------+-------------+---------------
estimated 10 MiB | 3 MiB | 13 MiB |

for months
bettini@bettini-laptop:~$ vnstat -m

ppp0 / monthly

month rx | tx | total | avg. rate
------------------------+--------------+--------------+---------------
Sep '09 243.74 MiB | 88.89 MiB | 332.62 MiB | 1.05 kbit/s
Oct '09 49.25 MiB | 15.68 MiB | 64.93 MiB | 0.64 kbit/s
------------------------+--------------+--------------+---------------
estimated 157 MiB | 48 MiB | 205 MiB |

and so on.

Very nice! :-)

Pubblicato da betto a 3:26 PM 0 commenti

Etichette: ,

Subscribe to: Posts (Atom)
 

AltStyle によって変換されたページ (->オリジナル) /