Gathering System Statistics in Linux, Part Two

Okay, so in the first part of this two-part howto, I covered how to setup collectd to run on your system to gather system statistics.  In this part, I’m going to cover setting up a frontend called CGP which will display the collectd data as graphs.

CGP is written in PHP, so you will need a webserver already serving up PHP pages to begin with.

Instead of using a release version of CGP, I went with checking out the git repo directly just because there were some bugs that have been fixed since the 0.3 release.

On your filesystem, you can check out the git repository into a directory that will be served publicly.

git clone

This will create a directory named “cgp”.

Next, open conf/config.php with an editor.   You will need to change the first directive, $CONFIG[‘version’] to 5 instead of 4.  Next, change $CONFIG[‘datadir’] to /usr/var/lib/collectd/rrd since that is where we specified the installation location in the first part of the howto.

The rest of the configuration options are fine with the defaults, but I’ll elaborate on a few of them.

$CONFIG[‘cat’][‘category1’], if set, will show the name of the hostnames to display on the first page.  The default is commented out, and it will just show the hostname of the computer by default.  So if you wanted to change this, it would just be for cosmetics, and you would put the hostname you want to display as the first and only option of the array.  For example: $CONFIG[‘cat’][‘category1’] = array(‘’);

The $CONFIG[‘overview’] option is another array.  This one specifies which collectd stats are shown, expanded, by default.  CGP will display all the stats that it supports reading from collectd, but they will be minimized by default, with an option to expand the sections.  The ones in this array are automatically expanded, so it’s just a matter of cosmetics and preference again.

When you view any of the graph stats, it will by default, show the statistics for the last 24 hours, or 86400 seconds.  You can change the default value with the $CONFIG[‘time_range’][‘default’] variable.  Just set it in the number of seconds.

There is one gotcha that is worth mentioning.  If there is any errors generated by the code, because it can’t read some RRD files for example, then it will break the output of the graph.  Depending on your browser, you will see a broken image icon in it’s place.  If you disable error reporting, then it will fix some of the displays.  You can disable error reporting in the conf/config.php file by adding this somewhere:

ini_set(‘error_reporting’, ‘E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_WARNING’);

That’s about it.  The last thing to do is load it up in your browser, and make sure it works.

There is one additional tweak I like to throw in, and that is putting the documents for CGP outside of the webroot, and creating an alias in Apache (my webserver of choice).  The reason for doing this is that if directories that look like they don’t belong often get deleted or forgotten about when migrating.  A separate directory keeps things nicely separated.

Setting up an alias means that a URL like will still work, despite that there is no directory named cgp in the root public directory of documents.

In addition to that, I also like to restrict access to the stats so I can only get them from my network connection at work.  Since we get a static IP address from our Internet provider, that is easy to accomplish.    If you’re interested in doing the same, here is the syntax you would add to the Apache configuration for both features:

Alias /cgp “/var/www/cgp”
<Directory “/var/www/cgp”>
AllowOverride None
Options None
Order deny,allow
Deny from all
Allow from

Once you made the changes to your httpd.conf, if using Apache, you can gracefully restart it.  Then browse to and you should see your spiffy statistics graphs.  Enjoy!

As with the previous article, I’ll keep this one as updated as is reasonable.  Feedback is welcome.

Document version: 1.1  Last update: 2011-11-08