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

Want to support HowtoForge? Become a subscriber!
 
Submitted by mrpurple (Contact Author) (Forums) on Mon, 2012-10-15 19:12. :: Ubuntu

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


 


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by AcidHawk (not registered) on Tue, 2012-10-30 08:14.
In case anybody else is getting this issue. I upgraded my Ubuntu 12.04 server to 12.10

When I ran the 

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

command  I kept getting a bdb (LoadError).  I searched for a quick solution but couldn't find one and eventually came across a suggestion for a different app also using Ruby and the Berkeley DB which suggested that I look to run an alternative ruby.

I noticed that in this install guide that libdb4.2-ruby1.8 was installed and guessed that that lib was meant for ruby 1.8 and not the newly installed one that came with the new Ubuntu.  All I had to do in the end was 

sudo update-alternatives --config ruby

and choose to use ruby 1.8 instead of ruby 1.9.1 and my philesight started working again.  I am sure there is a better solution to upgrade the libdb4.2-ruby1.8 to a newer version that plays nicely with Ruby 1.9.1 but I haven't found it yet.  In the meantime I can now monitor my disk space again.

 

Submitted by Thomas (not registered) on Fri, 2013-02-01 10:56.

On a clean install off 12.10, Rudy 1.9.1 is provide and not 1.8 anymore. So first you have to install ruby 1.8. You can do this by running

sudo aptitude install ruby build-essential libopenssl-ruby ruby1.8-dev

And then afterwards you can run

sudo update-alternatives --config ruby

And choose the ruby 1.8 version

Submitted by neofire (registered user) on Thu, 2012-10-25 11:54.
Hey i read this tutorial and had a look at the products website, and it looks good can it look at other ubuntu installations over the network or does it only work with a local installation ??
Submitted by mrpurple (registered user) on Wed, 2012-10-31 03:11.

It parses the HDD locally and then the web display is visible all over your network. Thats the point of the whole thing.

Philesight allows you to remotely monitor hard drive usage on headless servers.