Difference between revisions of "InfoInfo - vnStat"

From PeformIQ Upgrade
Jump to navigation Jump to search
 
Line 15: Line 15:
unarchiving it:  
unarchiving it:  


 
<pre>
  $ 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
Line 21: Line 21:
  $ make
  $ make
  $ sudo make install
  $ sudo make install
</pre>


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 28: Line 29:
contents:  
contents:  


 
<pre>
  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
</pre>


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 38: Line 40:
Next, initialise the database for each interface you wish to track:  
Next, initialise the database for each interface you wish to track:  


<pre>
  # /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
</pre>


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:  


<pre>
  # vnstat -i eth1 --short
  # vnstat -i eth1 --short
   
   
Line 50: Line 55:
       yesterday    82.15 MB  /  809.36 MB  /  891.52 MB
       yesterday    82.15 MB  /  809.36 MB  /  891.52 MB
           today    83.20 MB  /  704.07 MB  /  787.28 MB  /    907 MB
           today    83.20 MB  /  704.07 MB  /  787.28 MB  /    907 MB
</pre>


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
Line 55: Line 61:
the vnStat Web site. As well, a number of options are available so you can
the vnStat Web site. As well, a number of options are available so you can
view traffic data for the current days and months.
view traffic data for the current days and months.
[[Category:Articles]][[Category:Performance]]

Latest revision as of 12:33, 25 January 2008

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.