Setting up cacti on OS X

Setting up cacti on OS X for performance monitoring

Wed, 01 Aug 2007

Mac OS X Server can be overkill for many people. Mac OS X is more than capable for being a Web, Mail, DNS or any other kind of server. That said one item that has been missing for some, is performance monitoring.

So, what can you do?

Set up cacti as a reporting/graphing tool, in conjunction with other software already installed with Mac OS X.

For actual collecting of data on an individual machine, SAR does a wonderful job. Other instructions on the net suggest collections of bash/perl or Ruby scripts to ps/iostat/etc, but SAR is already on the machine and just needs a kick to get it going.

Set up sar
Add the following lines to cron to start data capture
0 0 * * * /usr/lib/sa/sa1 300 287
59 23 * * * /usr/lib/sa/sa2 -u

sa1 300 287 logs every 300 seconds, 287 times in total (287 * 300 = 86100 seconds ≈ 24hours)
sa2 -u rolls the sar data files

Then make scripts to capture from sar and store in snmp compatible files
sudo -s
cd /usr/local/
mkdir net-snmp
cd net-snmp
mkdir data scripts
cd scripts

create the 4 scripts (cpumon, diskmon, memmon, cacti_sar) that we need. (You can download them from here, then copy them to the new scripts folder. Remember to make them executable!)

On PowerPC based Macs, SNMP can be configured to enable access to the newly captured performance data.

Edit snmpd configuration
cd /usr/share/snmp/
nano snmpd.conf

contents of snmpd.conf
exec 1.3.6.1.4.1.2021.8.1.101 cpu /bin/cat /usr/local/net-snmp/data/cpu
exec 1.3.6.1.4.1.2021.8.3.101 disk /bin/cat /usr/local/net-snmp/data/disk
exec 1.3.6.1.4.1.2021.8.4.101 mem /bin/cat /usr/local/net-snmp/data/mem

Then add a snmp user
net-snmp-config --create-snmpv3-user -ro -a 'pass' snmpstats

On Intel based machines I haven't been able to get this to work. So instead we can grab the data files by an alternative method - http! Just set up a secure site/or directory that you can grab the cpu, disk & mem files from instead. We'll configure cacti later on how to get this data (rather than using the snmp data source). However adding the snmp user does let us get to the network stats via SNMP, so do this step on Intel as well.

Now we need to schedule the creation of the data files. Every 5 minutes should do the job. We also need to make certain the SNMP daemon is running.

create launchdaemon plist files in /System/Library so that they're always on (and not just when someone has logged in - this is a server after all)
cd /System/Library/LaunchDaemons
nano nz.co.hotblack.snmp-data.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>nz.co.hotblack.snmp-data</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/net-snmp/scripts/cacti_sar.bash</string>
</array>
<key>StartInterval</key>
<integer>300</integer>
</dict>
</plist>

nano nz.co.hotblack.snmp.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>nz.co.hotblack.snmp</string>
<key>ProgramArguments</key>
<array>
<string>/usr/sbin/snmpd</string>
<string>-r</string>
<string>-f</string>
</array>
<key>OnDemand</key>
<false/>
</dict>
</plist>

load launchdaemon
launchctl load -w nz.co.hotblack.snmp-data.plist
launchctl load -w nz.co.hotblack.snmp.plist

Right, everything is set to create the data, now we need something at the other end to gather and graph it. Coming soon - cacti.

return to list