Monday, September 15, 2008

HowTo: Monitor network traffic with vnStat on FreeBSD

vnStat is a console-based network traffic monitor. It keeps a log of
hourly, daily and monthly network traffic for the selected interface(s).

Bellow you'll find the needed steps for its installation and setup on FreeBSD 7.0:
  1. % su
  2. # cd /usr/ports/net/vnstat ; make install clean
  3. # rehash
  4. # ifconfig -a
  5. # vnstat -u -i rl0
  6. # cat /usr/local/share/doc/vnstat/vnstat-cron >> /etc/crontab
On steps 1 to 3 we basically became to the superuser, changed to the vnStat's port directory, proceeded by compiling the port and rehashing the shell.

Step 4 purpose is to find out the system network interface(s) in use, which in my case is rl0.

Finally with step 6 we've activated the cron job to feed vnStat's database following the port's supplied example.

To display the default statistics:
  • % vnstat
To display daily traffic statistics use the -d switch:
  • % vnstat -d
Monthly traffic statistics can be viewed with the -m switch:
  • % vnstat -m
To display current transfer rate for the selected interface in real time until interrupted:
  • % vnstat -l -i rl0
A nice list of switches can be viewed typing the following command:
  • % vnstat --help
And we're done. ;)

Further documentation is available at http://humdi.net/vnstat/.

3 comments:

Alexandre Nano said...

wow man... you're GOD in earth!! I was looking for a tool like this for a looooong time in the net!! Great!! Thanks a lot!!! nice post!! Keep goin'!!

tangram said...

Thanks Alex ;-)

Anonymous said...

Thank you sie.