Cacti on a MacOSX machine
Why?
Sometimes, you want to have everything under control. Or just have some nice graphs to watch during your long idle moments. Then cacti is something for you. It will allow you to monitor various values for various machines: bandwidth use for your router, CPU or hard disk use for your server, number of logged in users for your workstation… Cacti polls it for your using SNMP and then makes some nice graphs out of it.
How?
This article will briefly guide through setting up your random Intel Mac machine running Leopard (tested here on a MBP and iMac) to turn it into a Cacti server. Note that with that, you will be able to monitor any machine or device, running MacOSX or not, Linux or not, being an actual PC or not.
Step one will be to install the necessary Linux packages through Mac Ports. If you start from scratch, download the installer from the site, install it, and then run from Terminal
sudo /opt/local/bin/port -v selfupdate sudo /opt/local/bin/port install net-snmp rrdtool
You will also need to install MySQL for MacOSX from MySQL website. This will put a nifty panel in your System Preferences, make sure the MySQL engine is enabled before proceeding forward.
We will run Cacti as the cacti user on the system, so go and create it. Open System Preferences and go under the Accounts panel. Create a user named cacti, give it some password, and keep it a “Standard user”.
Now, from the Terminal, change to being the cacti user and let’s proceed onward:
su cacti cd ~ wget http://www.cacti.net/downloads/cacti-0.8.7d.tar.gz tar -zxvf cacti-0.8.7d.tar.gz ln -s ~/cacti-0.8.7d /Library/WebServer/Documents/cacti
Now time to deal with the database:
sudo mysqladmin -u root password <new password> sudo mysqladmin --user=root -p create cacti
Change directory to the cacti directory or give the full path to cacti.sql
mysql -u root -p cacti < cacti.sql sudo mysql -u root -p mysql mysql> GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'password'; exit;
Now, edit include/config.php with the right values based on what you used above:
$database_type = "mysql"; $database_default = "cacti"; $database_hostname = "localhost"; $database_username = "cacti"; $database_password = "password";
Data has to be polled at a regular interval, usually five minutes, so, still as cacti user, from Terminal, run
crontab -e
and append this line somewhere:
*/5 * * * * php /Library/WebServer/Documents/cacti/poller.php > /dev/null 2>&1
Now you should be able to access your Cacti server from http://localhost/cacti/ so just follow the on screen indications for a while.
Go in Configuration > Settings in the main page in the Console view, NET-SNMP version should be 5.x and RRDTool should be 1.2.x. Otherwise, you will never get any graphs.
Now we have to add some data sources.
- Go into Devices > Add > give the device a name, a description, and give its IP or hostname (start with localhost, it’s the easier). SNMP version 2, public should be your default choices. For my part, I have set that localhost to being a “Leopard host” (see templates below), and added those graph templates:Linux – Memory Usage, Unix – Load Average, Unix – Logged in Users, Unix – Processesand the following data queries:SNMP – Get Mounted Partitions, SNMP – Get Processor Information, SNMP – Interface Statistics, Unix – Mounted partitions.When adding the templates and queries to a host, check if they return a success or a failure (Status column). Also, you can check on top of the page to see if the host is even reachable at all (Ping Results and SNMP Information).
- As a second example, here is how to add a Web server to your Cacti monitoring. Add another device, I set it to “web server – apache” (see below how to import templates), device detection is set to Ping or SNMP (UDP ping).I have added the following graph templates:teMySQL – CPU Usage, teMySQL – Load Average, WebServer – Apache Statistics – Hits /s, WebServer – Apache Statistics – kBits / sand following data queries:
SNMP – Get Mounted Partitions, SNMP – Get Processor Information, SNMP – Interface statistics.
Some things to keep in mind:
- If you have a public server, using SNMP 1 or 2, you don’t have much possibility to securize the SNMP protocol. You might want to disable all rw access and change the community name in /etc/snmp/snmpd.conf, for instance I commented out a bunch of lines in mine:
[...]
#### # First, map the community name (COMMUNITY) into a security name # (local and mynetwork, depending on where the request is coming # from): # sec.name source community com2sec local 0.0.0.0 mycommunityrocks #com2sec mynetwork NETWORK/24 COMMUNITY #### # Second, map the security names into group names: # sec.model sec.name #group MyRWGroup v1 local group MyROGroup v2c local #group MyRWGroup usm local #group MyROGroup v1 mynetwork #group MyROGroup v2c mynetwork #group MyROGroup usm mynetwork #### # Third, create a view for us to let the groups have rights to: # incl/excl subtree mask view all included .1 80 #### # Finally, grant the 2 groups access to the 1 view with different # write permissions: # context sec.model sec.level match read write notif #access MyRWGroup "" any noauth exact all all all access MyROGroup "" any noauth exact all none none # -----------------------------------------------------------------------------
[...]
- Also, sometimes, you will be presented with data from a different host (usually localhost) than the host you are working on. Be careful not to add this data to your graphs! (in device / graphs views in Console)
- Which leads me to warn you that once data has been added to a device, you still need to create a graph about it, which will instruct Cacti to try to create the graph, and not just poll the values.
- Last point, it’s probably a good thing to browse around Cacti’s interface to really customize it to your needs. Graph trees for instance will help you make useful views for your graphs: by host, by data type, etc.
Templates
You can install some extra data presentation and fetching templates via the obvious “Import templates” in the Console view in Cacti’s GUI. I used the following templates:
- apachestats make sure to enable mod_status in your apache server and to copy ws_apachestats.pl into Cacti’s scripts folder.
- teMySQLcacti to monitor MySQL use (including innoDB)
- Leopard templates (I do not seem to remember where I found them, please contact me if you know about their source)
Extra templates can be found there for instance: http://www.debianhelp.co.uk/cactitemplates.htm
Result
Note that it will take some time before enough data is gathered and the graphs can start being created and displayed, be patient. Count a couple of hours.
Sources:
Because I simply didn’t invent all of that, below are the links I used as guide lines. I wrote this article because some were a bit outdated or concerned MacOSX server. Or simply because I prefer to have it all in one place.



Nice.
Ольга
May 16, 2009 at 01:33
Hi, interest post. I’ll write you later about few questions!
Kelly Brown
June 12, 2009 at 20:16