Other stuff here

External links

This is how I created the vnStati page. This assumes that you already have Apache and PHP running on your system and you are using the default Debian web root. First, make sure your repositories package list is up to date:

sudo apt-get update

Now, we need to install vnstat, vnstati and php5-gd:

sudo apt-get install vnstat vnstati php5-gd

Now, after 10 minutes or so, you can type vnstat in terminal and you should get some data. We can use vnstati to generate PNG images of this data for viewing in a web page. Lets create a directory in your web root to store the files:

sudo mkdir /var/www/vnstati

Now, we can make a shell script to generate the images. Make this outside the web directory somewhere, such as your home directory as we are doing here:

nano ~/vnstati.sh

Now paste in the following. Change eth0 to the device you wish to monitor if necessary:

Now hold CTRL + X, press Y and then ENTER to save the file. Next, we need to make vnstati.sh executable:

chmod +x ~/vnstati.sh

Now we can set up a Cron job to run our script every so often. Note if you use the default Apache document root of /var/www/ then you must add the Cron job as root. So, do:

sudo crontab -e

and add this line (edit path to vnstati.sh to suit). I use nice to give it a low priority, not that its a heavy process.
For updating every 5 minutes:

*/5 * * * * nice /home/pi/vnstati.sh >/dev/null 2>&1

Or for once an hour:

0 * * * * nice /home/pi/vnstati.sh >/dev/null 2>&1

Now hold CTRL + X, press Y and then ENTER to save the crontab. You should see:

crontab: installing new crontab

You should now have the image files being generated every 5 minutes (or every hour) in the location you chose. You can now make a html page to display the images and put that in the same folder as them. Feel free to use this basic html template I made here: template.html.

To use this template, we grab the template.html file from here and save it as index.html in /var/www/vnstati/ alongside our images:

I also edited the locale setting which is at the top of vnstat.conf as by default its set to:

Locale "-"

This was outputting the date in US format (M/D/Y) which is just weird (sorry fellow Americans!) You can check what your machine is using by doing 'locale' at the terminal. I changed it to the European format (D/M/Y) by changing this setting to:

Locale "en_GB.UTF-8"

Now hold CTRL + X, press Y and then ENTER to save the configuration file.

If you found this page helpful, please leave a comment in my guestbook. A link to your stats page would be good too!