Difference between revisions of "InfoInfo - vnStat"
PeterHarding (talk | contribs) (New page: = Monitor bandwidth with vnStat = Vincent Danen, TechRepublic Keeping track of bandwidth usage is a good thing for a variety of reasons, particularly in situations where bandwidth account...) |
PeterHarding (talk | contribs) |
||
Line 15: | Line 15: | ||
unarchiving it: | unarchiving it: | ||
$ curl -O http://humdi.net/vnstat/vnstat-1.4.tar.gz | $ curl -O http://humdi.net/vnstat/vnstat-1.4.tar.gz | ||
$ tar xvzf vnstat-1.4 | $ tar xvzf vnstat-1.4 | ||
$ cd vnstat-1.4 | $ cd vnstat-1.4 | ||
$ make | $ make | ||
$ sudo make install | $ sudo make install | ||
If you're building on a 64-bit platform, use make 64bit instead. | If you're building on a 64-bit platform, use make 64bit instead. | ||
Line 29: | Line 28: | ||
contents: | contents: | ||
0-55/5 * * * * if [ -x /usr/local/bin/vnstat ] && [ `ls /var/lib/vnstat/ | | 0-55/5 * * * * if [ -x /usr/local/bin/vnstat ] && [ `ls /var/lib/vnstat/ | | ||
wc -l` -ge 1 ]; then /usr/local/bin/vnstat -u; fi | wc -l` -ge 1 ]; then /usr/local/bin/vnstat -u; fi | ||
This assumes vnStat is installed in /usr/local and also assumes that | This assumes vnStat is installed in /usr/local and also assumes that | ||
Line 40: | Line 38: | ||
Next, initialise the database for each interface you wish to track: | Next, initialise the database for each interface you wish to track: | ||
# /usr/local/bin/vnstat -u -i eth0 | |||
# /usr/local/bin/vnstat -u -i eth0 | # /usr/local/bin/vnstat -u -i eth1 | ||
# /usr/local/bin/vnstat -u -i eth1 | |||
Once this is done, the cron job will take care of the rest. Wait for the | Once this is done, the cron job will take care of the rest. Wait for the | ||
cron job to execute a few times and then you can view the data using: | cron job to execute a few times and then you can view the data using: | ||
# vnstat -i eth1 --short | |||
# vnstat -i eth1 --short | |||
rx / tx / total / estimated | rx / tx / total / estimated | ||
eth1: | |||
yesterday 82.15 MB / 809.36 MB / 891.52 MB | |||
today 83.20 MB / 704.07 MB / 787.28 MB / 907 MB | |||
A PHP front-end exists, which is very easy to configure, allowing you to | A PHP front-end exists, which is very easy to configure, allowing you to |
Revision as of 13:24, 12 December 2007
Monitor bandwidth with vnStat
Vincent Danen, TechRepublic
Keeping track of bandwidth usage is a good thing for a variety of reasons, particularly in situations where bandwidth accounting is required, such as paying for Internet services that are dependent upon the amount of bandwidth used.
One great tool for Linux is vnStat, which is available from http://humdi.net/vnstat/ (http://humdi.net/vnstat/). Some Linux distributions may bundle vnStat, but it is more likely that you will have to build it from source.
Begin by downloading the vnStat source tarball from the Web site and unarchiving it:
$ curl -O http://humdi.net/vnstat/vnstat-1.4.tar.gz $ tar xvzf vnstat-1.4 $ cd vnstat-1.4 $ make $ sudo make install
If you're building on a 64-bit platform, use make 64bit instead.
Next, create a cronjob to execute vnStat every five minutes to collect the bandwidth usage data. For instance, create /etc/cron.d/vnstat with the contents:
0-55/5 * * * * if [ -x /usr/local/bin/vnstat ] && [ `ls /var/lib/vnstat/ | wc -l` -ge 1 ]; then /usr/local/bin/vnstat -u; fi
This assumes vnStat is installed in /usr/local and also assumes that /etc/cron.d is a location for system-run cron jobs (which is the default for most Linux distributions).
Next, initialise the database for each interface you wish to track:
# /usr/local/bin/vnstat -u -i eth0 # /usr/local/bin/vnstat -u -i eth1
Once this is done, the cron job will take care of the rest. Wait for the cron job to execute a few times and then you can view the data using:
# vnstat -i eth1 --short rx / tx / total / estimated eth1: yesterday 82.15 MB / 809.36 MB / 891.52 MB today 83.20 MB / 704.07 MB / 787.28 MB / 907 MB
A PHP front-end exists, which is very easy to configure, allowing you to view the data in a nicely presented Web graph; you can download this from the vnStat Web site. As well, a number of options are available so you can view traffic data for the current days and months.