How To Monitor Hard Drive Usage In Ubuntu Server Using The Visual Philesight CGI Script

This process will add a nice visual representation of the hardrive usage on your Ubuntu server which you can acces over your local network. It's based on "philesight" which is a nice clone of philelight. Philesight is available at http://zevv.nl/play/code/philesight/.

Assuming you already have an Ubuntu LAMP (linux apache mysql php) server with the web root at /var/www and have accesss to the ubuntu terminal carry, out the following.

Install dependancies:

sudo apt-get install libdb4.2-ruby1.8 libcairo-ruby1.8 libapache2-mod-perl2 libapache2-mod-php5 ruby

Enable cgi scripting if not already:

sudo mkdir /usr/lib/cgi-bin
sudo chmod 755 /usr/lib/cgi-bin

Edit your apache2 site file:

 sudo nano /etc/apache2/sites-available/default

Make sure there is a section that reads as follows:

         ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

Close and save (ctrl-x then y).

Get philesight:

mkdir ~/downloads
cd ~/downloads
sudo wget http://zevv.nl/play/code/philesight/philesight-20120427.tgz

Unzip philesight and move it into the desired directory.

tar -xvf philesight-20120427.tgz
sudo mv philesight-20120427 philesight
cd philesight

Move the ruby functions into place and make them executable:

sudo mv philesight /usr/bin/philesight
sudo mv philesight.rb /usr/bin/philesight.rb
sudo chmod a+x /usr/bin/philesight
sudo chmod a+x /usr/bin/philesight.rb

Edit the philesight file to correctly locate itself when called from a cron job:

sudo nano /usr/bin/philesight

Edit the line which currently reads:

require 'philesight'

to read instead:

require '/usr/bin/philesight'

Close and save.

Prepare directory database:

cd /usr/bin/
sudo /usr/bin/philesight --db /usr/lib/philesightdb --index /

This may take some time to run depending on the amount of data on your harddrive.

Prepare your web files:

cd ~/downloads/philesight
sudo nano philesight.cgi

Edit the following parameters to read as follows:

 $path_db = "/usr/lib/philesightdb"

Exit and save.

Copy the cgi script into place and make it executable:

sudo mv philesight.cgi /usr/lib/cgi-bin/philesight.cgi
sudo chmod a+x /usr/lib/cgi-bin/philesight.cgi

Make the ruby scripts available to the cgi file:

sudo ln -s /usr/bin/philesight.rb /usr/lib/cgi-bin/philesight.rb
sudo chmod a+x /usr/bin/philesight.rb

Reload the webserver:

sudo apache2ctl restart
sudo service apache2 restart
sudo /etc/init.d/apache2 force-reload

The hard drive usage of your server will now be available at:

http://your_server_name/cgi-bin/philesight.cgi

When you first load it you may see a graph indicating that 100% of your Hard disk is useed up by "proc". Ignore this and scrole down and you will see a list of folders located in the root directory. Clicking on each of these will give a visual representation of the material containined with in each.

Now we're going to add a cron job so the images update at least daily.

sudo nano /etc/cron.daily/philesight

Copy in the following lines then close and save:

#!/bin/sh
sudo rm /usr/lib/philesightdb
sudo /usr/bin/philesight --db /usr/lib/philesightdb --index /

Now make that cron job executable:

sudo chmod a+x /etc/cron.daily/philesight


 

Share this page:

4 Comment(s)