VNStat On FreeBSD 7 With A PHP GUI

I installed VNStat and the PHP GUI to be able to view basic information regarding incoming and outgoing traffic per interface. I am using FreeBSD 7 with PHP4, as I had problems setting the GUI up with PHP5. If you can get it to work in PHP5, please do let me know.

To install PHP4, type the following:

cd /usr/ports/lang/php4 && make install clean

I selected all options to be installed, as I use PHP for other websites and applications as well. Your options might be different than mine, but the defaults should work fine.

Also install the gd shared extension for php

cd /usr/ports/graphics/php4-gd && make install clean

Options for php4-gd-4.4.8:

[X] T1LIB     Include T1lib support
[X] TRUETYPE  Enable TrueType string function

The application can be obtained from here: http://www.sqweek.com/sqweek/index.php?p=1
I downloaded the file to "/usr/local/src".

Please note that I am not the creator of the PHP GUI, I found it usefull and it suited my needs 100%. There are extra notes and contact details on the download site.

I installed Apache 2 on my system, as I am more familiar with the configuration and settings of Apache 2. I then proceeded to create the directories for the interface.

cd /usr/local/www/data
mkdir old
mv * old/
mkdir vnstat.test.local

I usually remove the default Apache files in the document root and also add my own redirect file as I make use of virtual hosts.

Extract the downloaded files into "/usr/local/www/data/vnstat.test.local".

Edit the "httpd.conf" and add the virtual host settings.

vi /usr/local/etc/apache2/httpd.conf

Add the following entry at the bottom of the page:

<VirtualHost *:80>
         DocumentRoot /usr/local/www/data/vnstat.test.local
         ServerName vnstat.test.local
</VirtualHost>

I kept the entry as basic as possible, but you can refer to the Apache documents on how to add log entries etc.

Make sure the following entry is in "/etc/rc.conf":

apache2_enable="YES"

This will ensure that Apache starts up at boot time.

Then restart Apache, you can either do a full restart:

/usr/local/etc/rc.d/apache2 restart

Or if you currently have sites up and running on a live system, it is advisable to do a graceful restart, so that current connections are not broken.

/usr/local/sbin/apachectl graceful

Find the "vnstat" binary file:

which vnstat

Should return "/usr/local/bin/vnstat".

If not, you need to install it with the following command:

cd /usr/ports/net/vnstat && make install clean

Then try the previous command again.

Add the line into the "config.php" file, which is in "/usr/local/www/data/vnstat.test.local":

$vnstat_bin = '/usr/local/bin/vnstat';

Also configure the interfaces to be monitored in the same file:

$iface_list = array('le0', 'ppp0');
   
$iface_title['le0'] = 'Internal';
$iface_title['ppp0'] = 'Internet';

Please take note that your interface system names could very well be different than mine.

From the command line, run:

vnstat -i le0

Check the VNStat manual pages for more options regarding the "vnstat" command.

I added an entry into my client machines hosts file:

<ip address of the server> vnstat.test.local

I waited a few minutes as VNStat does take some time to gather information before anything is displayed. Then I browsed to the hostname and voilà, I could see my bandwidth usage on the configured interfaces.

Share this page:

0 Comment(s)