On GameSpot: Wii Fit tells 10-year-old she's fat

Monitor bandwidth with vnStat

Tags: OPEN SOURCE, UNIX, Operating systems, monitor, Vincent Danen, vnStat, Linux, Linux Tips Newsletter

  • Save
  • Print
  • Digg This
  • 4

Takeaway: Vincent Danen helps you get started using the Linux tool vnStat to monitor your bandwidth usage.

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/. 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, initialize 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.

Delivered each Tuesday, TechRepublic's free Linux NetNote provides tips, articles, and other resources to help you hone your Linux skills. Automatically sign up today!

  • Save
  • Print
  • Digg This
  • 4

Print/View all Posts Comments on this article

vnstat on Redhat EL AS4hariog@...  | 05/29/07
Yes, it shouldvdanen  | 06/02/07
Anything for Windows Environments???stephenh@...  | 05/31/07
Sorry, no suggestionsvdanen  | 06/02/07
Try some VMWare virtual appliancesTTate  | 06/04/07

What do you think?

Article Categories

Security
Security Solutions, IT Locksmith
Networking and Communications
E-mail Administration NetNote, Cisco Routers and Switches
CIO and IT Management
Project Management, CIO Issues, Strategies that Scale
Desktops, Laptops & OS
Windows 2000 Professional, Microsoft Word, Microsoft Excel, Microsoft Access, Windows XP,
Data Management
Oracle, SQL Server
Servers
Windows NT, Linux NetNote, Windows Server 2003
Career Development
Geek Trivia
Software/Web Development
Web Development Zone, Visual Basic, .NET
advertisement
Click Here