How to install collectd on Ubuntu.

Some time ago I found out about collectd and I was curious to see what it does. collectd collects statistics about the machine its running on - cpu, disk, memory, processes, battery, etc.

Here's how to install it on Ubuntu and visualize the data it has collected.


Step 1: Install the collectd package.

Easy, just install the package:

sudo apt-get install collectd


Step 2: Make sure collectd and apache are running.

If you have installed apache, you should have both collectd and apache running

$ sudo service --status-all | egrep "collectd|apache2"
 [ + ]  apache2
 [ + ]  collectd

If collectd is not running, run sudo service collectd start. For me at least, it was running after installation.


Step 3: Install collectd's web app for generating graphs.

Ok, now we have collectd running. collectd is mostly about collecting data and it allows other frontends to display it. However, it comes with a simple set of cgi scripts that can be used to see some graphs.

In the /usr/share/doc/collectd/examples/ directory, you'll find a directory named collection3. Copy the entire directory to /var/www/html:

$ sudo cp -r ./collection3 /var/www/html.


Step 4: Enable apache to run CGI scripts.

Great, you can now access the cgi scripts by going to this url: http://localhost/collection3/bin/index.cgi. However, you'll be served a text file, since apache doesn't know to run these cgi scripts. There's is a simple manual explaining cgi scripts in Apache.

You'll have to do two things.

First, you need to install the cgi module. So, go to /etc/apache2/mods-enabled and run this: $ sudo ln -s ../mods-available/cgi.load. You have now enabled the cgi module.

Next you'll have to change apache2.conf, located in /etc/apache2 (Ubuntu doesn't use httpd.conf).

Add these lines to it:

<Directory /var/www/>
        Options +ExecCGI
        AddHandler cgi-script .cgi
</Directory>

And - you're done! If you go to http://localhost/cgi-bin/collection3/bin/index.cgi, you should see some graphs.

social