vnstat Network stats on your eTRAYZ

I want to monitor the network usage on my eTRAYZ. So I installed vnstat and a php frontend.
Here’s a guide.

1. Install vnstat using ipkg.

ipkg update
ipkg install vnstat

2. Create vnstat database.
vnstat -u -i eth0

3. Change to the web folder and download the PHP frontend

cd /home/sysadmin/WWW
wget http://www.sqweek.com/sqweek/files/vnstat_php_frontend-1.4.tar.gz

4. Expand the archive, delete it and rename the folder
tar xvzf vnstat_php_frontend-1.4.tar.gz
rm vnstat_php_frontend-1.4.tar.gz
mv vnstat_php_frontend-1.4 vnstat

5. Change to the new directory and edit config.php using command

cd vnstat
vi config.php

and change the variable $iface_list so that the line reads
$iface_list = array('eth0');

6. Delete these two lines:
$iface_title['eth1'] = 'Internet';
$iface_title['sixxs'] = 'SixXS IPv6';

If you want you can change the friendly name for $iface_title[‘eth0’]. Do not change the definition of variable $vnstat_bin, this must be left blank because the php script that calls vnstat uses a “\” which is not allowed by the php service in safe mode. Safe and quit vi.

7. Consequently we have to set up a cronjob to dump the vnstat data in to the “dumps” directory defined in variable $data_dir. Make the directory dumps:
mkdir dumps

8. Now we need to make a script and cronjob to update the nvstat data and create the dumpfile. Make a folder for your scripts
mkdir /home/sysadmin/my_scripts

9. Create a script file for cronjob to run
vi /home/sysadmin/my_scripts/vnstatdump.sh
…and paste the following lines into it

#!/bin/bash
/opt/bin/vnstat -u
sleep 10
/opt/bin/vnstat --dumpdb -i eth0 >> /home/sysadmin/WWW/vnstat/dumps/vnstat_dump_eth0

10. Make the script executable by doing:

chmod +x /home/sysadmin/my_scripts/vnstatdump.sh

and test the script by running it
sh /home/sysadmin/my_scripts/vnstatdump.shvnstatdump.sh

There shouldn’t be any error messages.

11. Create the cronjob schedule

vi /etc/crontab

… and enter new lines for however frequently you want the web page data to be updated. For instance to have it updated every hour at 1 minute past the hour enter a line like
1 * * * * root /home/sysadmin/my_scripts/vnstatdump.sh

12. Restart crond, i.e. “crond restart”
Use your internet browser and open the index.php page: http://etrayz/vnstat/index.php. Done.

Leave a Reply

Your email address will not be published. Required fields are marked *