y=x

Naturally, when you want awesome graphs, flexibility, awesome graphs, SNMP polling, and awesome graphs, you turn to Cacti. Cacti is a web application written in PHP that can graph statistics collected from hosts of your choosing. Hosts are polled with SNMP, the de-facto standard in network device monitoring and control.

Cacti CPU Temperature Graph Today, much to my dismay, I discovered that compiling Cacti’s dependencies correctly and getting it to just ‘work’ can be a pain in the ass on Mac OS X. I also discovered that there is no consolidated guide to setting up Cacti + RRDTool + SNMP on any platform, which would’ve saved me a few hours of work. Not to mention drastically reducing the number of Google searches I have to make and the tinkering I have to do to figure out how something works. Which is why I’ve decided to make one, and update it with useful information.

Disclaimer

There is lots of minimal configuration going on here. You may want more configuration for the applications built, or to use a preexisting installation, or to have better security. This is just a basic guide for someone who wants Cacti up and running quickly, from scratch. I highly suggest that you use a password for MySQL and password protect the Apache server running Cacti, or use SSL, or both, but I won’t go over that here.

Let’s Put Everything in /opt

Just for fun, we’re going to shove everything in /opt and call it a day. /opt is really just an easier-to-type /usr/local without a preexisting subdirectory structure, and we’re going to use it in a way that isolates each package, making multiple packages easier to maintain.

MySQL

./configure --prefix=/opt/mysql && make && sudo make install && sudo make init-db

Apache2

./configure --prefix=/opt/apache2 --enable-so && make && sudo make install

PHP

./configure --prefix=/opt/php --with-apxs2=/opt/apache2/bin/apxs --with-mysql=/opt/mysql && make && sudo make install

Configuration

Edit /opt/apache2/conf/httpd.conf and add the following line:

AddType application/x-httpd-php .php

Find the DirectoryIndex parameter and add index.php to the list.

DirectoryIndex index.php index.html ...

Next Up: Dependencies

We should have a working MySQL + Apache2 + PHP setup now. The next things we need are SNMP, which OS X graciously has installed by default, so we don’t have to worry about that, and RRDTool, which Cacti uses for graphing and log files.

RRDTool has several dependencies, one of which is very easy to miscompile (more about that in a moment). The dependencies are: libpng, libart, freetype2, and it doesn’t hurt to first build pkgconfig, which RRDTool can use to locate these dependencies.

pkgconfig

Just put pkgconfig in the default path, /usr/local/bin, which should be part of $PATH.
./configure && make && sudo make install

libpng

./configure --prefix=/opt/libpng && make && sudo make install

libart

./configure --prefix=/opt/libart && make && sudo make install

freetype2

Here’s the tricky one. I had to scour the internet to figure this one out: you’re going to need to set the following environment variables BEFORE you compile freetype2.

export LDFLAGS="-framework Carbon"; export CPPFLAGS=$LDFLAGS

If you don’t do this, it will compile fine, and RRDTool will bail when producing graphs, producing the following error message:

dyld: Symbol not found: _FSPathMakeRef

After setting the environment variables, we can build freetype:

./configure --prefix=/opt/freetype2 && make && sudo make install

Rolling it all together: RRDTool

First, let’s put those dependencies in our pkgconfig path.

export PKG_CONFIG_PATH=/opt/libpng/lib/pkgconfig:/opt/libart/lib/pkgconfig:/opt/freetype2/lib/pkgconfig

Also, check that pkgconfig is in your path and that it runs OK.

We’re also going to need to disable python support, since the python that ships with OS X breaks this. Now we can build:

./configure --prefix=/opt/rrdtool --disable-python && make && sudo make install

Configuring Cacti

We’re now ready for the fun part. Untar Cacti to /opt/apache2/cacti, and CD to it.

We’re going to need to turn on the MySQL server:

sudo /opt/mysql/bin/mysqld_safe >dev/null 2>&1 &

This should background the server. To test it:

/opt/mysql/bin/mysql -u root

This should yield a MySQL console logged in as root. Issue the following command in the MySQL shell:

create database cacti;

Quit out of MySQL and load the cacti.sql file in your cacti installation:

/opt/mysql/bin/mysql -u root cacti < cacti.sql

Your cacti database should now be populated. Now you can start apache2 and begin the web configuration:

sudo /opt/apache2/bin/apachectl start

Coming in Part 2

Graph/host/data templates, backend ruby scripts to parse CPU load, temperature, and disk usage from commandline utilities, and using SNMP to run custom commands.