Graph Network Performance with Cacti

Essential Open Source Network Administration Tools


1. Introduction
1.1. Document conventions
2. Install Cacti Prerequisites
2.1. Install MacPorts
2.2. Install NeDi (optional)
2.3. Install MySQL 5
2.4. Install PHP
3. Install and Configure Cacti
3.1. Install Cacti
3.2. Set Cacti Permissions
3.3. Create the Cacti DB
3.4. Edit Cacti config.php
3.5. Setup Plugin Support
3.6. Set the Poller in cron
4. Login to Cacti
5. Support Information

1. Introduction

Cacti is an open source RRDtool-based graphing system that uses PHP/Apache for its interface and stores configuration data in a MySQL database. It scales well and may be used within large enterprise network environments. It also supports a robust plugin architecture that allows powerful Cacti plugins, such as Network Weathermap.

This HOWTO does not cover creating graphs using Cacti's interface (for this refer to the Cacti docs) because I prefer to create graphs using the NeDi Cacti API, and I think using Cacti with NeDi is superior to using Cacti alone because NeDi adds robust device discovery and interface browsing and selection. Creating Cacti graphs with NeDi's Cacti API is stunningly simple and easier than creating graphs within the Cacti interface itself.

1.1. Document conventions

Here are the conventions used to distinguish Unix terminal window input and output.

%% Commands to be typed into a terminal window.
Command output to a terminal window.
File text.

2. Install Cacti Prerequisites

This section covers installing general support software required for Cacti -MySQL and the PHP scripting language.

2.1. Install MacPorts

You may install the MacPorts package manager with these instructions, which include instructions for installing XWindows (X11). Follow the instructions carefully and perform all non-optional steps.

2.2. Install NeDi (optional)

NeDi has a Cacti API that makes Cacti graph creation within NeDi far easier than within Cacti's own web interface, so I highly recommend interrupting the Cacti install at this point and installing NeDi. Then continue the Cacti install by skipping the rest of this section (NeDi prerequisites include MySQL5 and PHP5) and resume at Install and Configure Cacti.

before installing NeDi to use with Cacti. If you install NeDi to use with Cacti, skip the rest of the prerequisites section since the NeDi prerequisites also include MySQL5 and a MacPorts install of PHP5 to provide SNMP support.

Note

To use the NeDi Cacti API, Cacti must be installed on the same host as NeDi.

2.3. Install MySQL 5

MySQL is used to store the data necessary for Cacti configuration and operation.

  1. Install MySQL with MacPorts

    %% sudo port install mysql5 +server
  2. Execute the mysql_install_db5 command to do a first-time setup for MySQL5.

    %% sudo -u mysql mysql_install_db5
  3. Start MySQL and set it to run at system boot.

    %% sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
  4. Verify the MySQL process is running with this command.

    %% ps -ax | grep mysql

    If MySQL is running you will see output similar to this.

    26683  ??  Ss     0:00.05 /opt/local/bin/daemondo --label=mysql5 --start-
    26692  ??  S      0:00.02 /bin/sh /opt/local/lib/mysql5/bin/mysqld_safe -
    26712  ??  S      0:16.90 /opt/local/libexec/mysqld --basedir=/opt/local 
    20796  p2  R+     0:00.00 grep mysql
  5. Set the MySQL root password.

    %% sudo /opt/local/lib/mysql5/bin/mysqladmin -u root password <mypassword>
  6. Perform a MySQL root account login test with the new root password.

    %% mysql5 -u root -p

2.4. Install PHP

You may install PHP from any source, but a good PHP 5 binary installer that works with Apple's built-in Apache is Marc Liyanage’s PHP 5 package. Just download it, run the installer, do an “easy install”, and afterwards edit the file /usr/local/php5/lib/php.ini for MacPorts' MySQL5 as shown.

mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock

To activate PHP after installation, restart Apache.

  1. Go to System Preferences on the Apple menu.

  2. Click the Sharing icon.

  3. Check the Web Sharing checkbox, or remove the check and check it again.

To test PHP, create a file named test.php in /Library/WebServer/Documents that contains the line shown below.

<?php phpinfo() ?>.

Now open url http://localhost/test.php in your web browser. If PHP is working properly you will see a PHP status table.

3. Install and Configure Cacti

Here we install Snort, import the Snort MySQL database schema, and configure Snort.

3.1. Install Cacti

Use these steps to install Cacti via MacPorts. If you plan to use Cacti plugins, such as Network Weathermap, you must use the “plugins” MacPorts variant as shown below. Otherwise, you may omit this variant.

%% sudo port install cacti +plugins

After the Cacti install is complete, set a symlink for Cacti inside your Apache document root.

%% sudo ln -s /opt/local/share/cacti/  /<Apache-docroot>/cacti

3.2. Set Cacti Permissions

The Cacti files should be flagged to the same owner as your Apache user. The default Apache user on OS X is "www", so you may just use that as your Apache user as shown in the example below.

%% sudo chown -R www:www /opt/local/share/cacti/

3.3. Create the Cacti DB

Login to MySQL as the root user.

%% mysql5 -u root -p

Once logged into MySQL as root, create a Cacti database and user, and set the database permissions.

mysql> grant CREATE,INSERT,SELECT,DELETE,UPDATE on cacti.* to cacti@localhost;
mysql> grant CREATE,INSERT,SELECT,DELETE,UPDATE on cacti.* to cacti;
mysql> SET PASSWORD FOR cacti@localhost = OLD_PASSWORD('<cactidb-pwd>');
mysql> create database cacti;
mysql> exit

Now import the Cacti database schema.

%% cd /opt/local/share/cacti
%% sudo cat cacti.sql | mysql5 –u root –p cacti

Finally, login to MySQL as root and show the Cacti tables to verify the Cacti database schema was imported.

%% mysql5 –u root –p

mysql> use cacti;
mysql> show tables;

The Cacti database tables display as shown.

+--------------------------------+
| Tables_in_cacti                |
+--------------------------------+
| cdef                           | 
| cdef_items                     | 
| colors                         | 
| data_input                     | 
| data_input_data                | 
| data_input_fields              | 
| data_local                     | 
| data_template                  | 
| data_template_data             | 
| data_template_data_rra         | 
| data_template_rrd              | 
| graph_local                    | 
| graph_template_input           | 
| graph_template_input_defs      | 
| graph_templates                | 
| graph_templates_gprint         | 
| graph_templates_graph          | 
| graph_templates_item           | 
| graph_tree                     | 
| graph_tree_items               | 
| host                           | 
| host_graph                     | 
| host_snmp_cache                | 
| host_snmp_query                | 
| host_template                  | 
| host_template_graph            | 
| host_template_snmp_query       | 
| poller                         | 
| poller_command                 | 
| poller_item                    | 
| poller_output                  | 
| poller_reindex                 | 
| poller_time                    | 
| rra                            | 
| rra_cf                         | 
| settings                       | 
| settings_graphs                | 
| settings_tree                  | 
| snmp_query                     | 
| snmp_query_graph               | 
| snmp_query_graph_rrd           | 
| snmp_query_graph_rrd_sv        | 
| snmp_query_graph_sv            |
+--------------------------------+
70 rows in set (0.09 sec)

3.4. Edit Cacti config.php

Edit Cacti's config.php file.

%% cd /opt/local/share/cacti/include
%% sudo pico config.php

Modify the MySQL variables.

$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "<my-cacti-password>";

3.5. Setup Plugin Support

Plugin support is optional, and may only be used if you installed Cacti with the “plugins” MacPorts variant. However, if you installed Cacti with plugin support, then you must setup plugin support properly for your Cacti installation to work.to functionthere are some additonal steps to perform.

  1. Import the PA schema

    %% cd /opt/local/share/cacti
    %% sudo cat pa.sql | mysql5 -u root -p cacti
  2. Set the Cacti URL in file /opt/local/share/cacti/include/global.php to /cacti/ as shown (including the trailing “/”)

    $config['url_path'] = '/cacti/';
  3. Download and unzip the Cacti plugin(s) you wish to use to the directory /opt/local/share/cacti/plugins, and set the permissions of the plugin files to the Unix user chosen to run Cacti (www in this example). There is a MacPorts port for the Network Weathermap Cacti plugin, so copying and unpacking it manually is not necessary, as shown below.

    %% sudo port install network-weathermap
    %% sudo chown -R www:www /opt/local/share/cacti/plugins/
  4. Edit /opt/local/share/cacti/include/global.php and add an entry for each plugin you installed after the “plugins” statement.

    $plugins = array();
    $plugins[] = 'weathermap';

    Note

    You must enable plugin(s) in the Cacti web interface for your Cacti user. See the section Login to Cacti.

3.6. Set the Poller in cron

To collect graph data from devices, Cacti uses a poller. It is set to run via cron, typically every 5 minutes.

  1. Run the Cacti poller manually for the first time to verify it is operating correctly. If you are using another user to run Cacti besides the user “www”, substitute that user in the example below. If you have no errors you may proceed to setup cron for polling.

    %% sudo -u www /opt/local/bin/php /opt/local/share/cacti/poller.php
  2. Edit the Cacti user's crontab; the Cacti user is “www” here.

    %% sudo -u www crontab -e
  3. Set the Cacti poller in cron to poll devices every 5 minutes.

    */5 * * * *  /opt/local/bin/php /opt/local/share/cacti/poller.php > /dev/null 2>&1

4. Login to Cacti

Start your web browser and go to: http://localhost/cacti to login to the Cacti web interface. The default user/password is admin/admin.

After logging in, you'll see the Cacti console window as shown below.

After logging into the Cacti interface, you should immediately set Cacti to use RRDtool 1.2.x, the version that was installed as a Cacti dependency by MacPorts. The rest of the settings should be fine at the defaults.

If you installed Cacti with plugin support and installed plugin(s), you must enable the plugin(s) in the Cacti web interface for your Cacti user. To do so, enter Console -> User Management, check the appropriate plugin checkboxes in the Realm Permissions pane as shown below, and click Save.

If the plugin(s) were installed correctly, after checking the boxes in the Realm Permissions pane, you will see a new top-level tab in the Cacti interface as shown below for the Network Weathermap plugin.

This completes the Cacti install with optional plugin support. For easy graph creation, I recommend creating your Cacti graphs using NeDi, a great tool in its own right. NeDi discovers all your network devices automatically and allows you to effortlessly select interfaces for Cacti graphs using the Cacti API. To create graphs natively within Cacti, you should read the Cacti documentation.

5. Support Information

To get help with Cacti, you should first consult the documentation. If that doesn’t help you may ask questions in the Cacti forums. Before asking a question, be sure to search the forum to see if your question has already been asked.