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.
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.
[…] In the first part, I covered building and installing Cacti from scratch on an OS X machine. Now I will guide you through setting up SNMP on your other OS X machines. I put together a package of some scripts I made to extract CPU usage, disk activity, and temperature (for OS X Server), which will be executed and read when Cacti polls the SNMP server. […]
“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.”
Nah it’s easy. One command installs Cacti and its dependencies if you use DarwinPorts. That just leaves PHP -no need to replace OS X’s built-in Apache- just use a PHP 5 binary (http://www.entropy.ch/software/macosx/php/) and you’re in business 60 seconds later. You could also check out a Cacti competitor that I think works better -NetMRG. http://homepage.mac.com/duling/halfdozen/NetMRG-Howto.html
Oh I forgot, the DarwinPorts Cacti port spits out a min-HOWTO at the end to tell how to get it all up and running.
Surprisingly enough, like you I prefer to use existing dependancies whenever possible but I’m not a darwinports fan since the whole darwinports process is an experimental one and I don’t use anything experimental for production use unless I absolutely have too.
I’ve had extensive experience with RRDTool and have provided code to Tobias which is used in the RRDTool binaries and I’ve rewritten the old and abandoned php_rrdtool to work in PHP4/5 and with 1.0x and 1.2x versions of RRDTool (http://daleenterprise.com/rrdtool_info.php).
I didn’t bother to install freetype because installing X11 provides this dependancy and since I’m running OSXS the same holds true for MySQL.
I did generate my own version of PHP, not that I didn’t like the entrophy PHP as a generic install but because I found some incompatabilities with the build on a PPC Mac that concerned me (I’ve addressed these issues with Marc and they are being corrected).
Once the dependancies are in place Cacti is pretty easy to install make some minor modification to utilize the PHP RRDTool functions from within PHP rather than from the RRDTool binary.
I adopted the old amavis-stats project since it’s abandonment and it’s gone through some considerable changes but it is a good indication that the PHP RRDTool module is useable and a less time consumming method of generating graphs.
One more thing, the reason that python breaks is becasue of the method in which apple implemented it, RRDTool can be built and used with python without issue if you adjust the buildprocess to compensate for it, I have an install RRDTool-1.0.49 and RRDTool-1.2.11 in 10.4 that works in python without crashing so I know that depending on your programming knowledge you can generate the same working results.
I have your scripts running nicely on all my PPC macs. I have a few intel macs and for some reason snmp is broken on them. I tried compiling snmp myself, but to no avail.
I read somewhere that this has something to do with the x86 kernel build, but I have no idea whats missing.
Error:
SNMPv2-SMI::enterprises.2021.8.1.101.101.1 = No Such Object available on this agent at this OID