Monitoring and Graphing Your Network With Cacti

0
10041

A-man-touching-cacti-technologyCacti, an open source network graphing application, utilises RRDTool, a data logging and graphing system for time series data. Read on to learn more about it.

Cacti monitors both the incoming and the outgoing ADSL traffic on my Cisco 877W ADSL router. In the absence of a router that supports SNMP, your own Linux machine or another device can be monitored. At the time of writing, the latest Cacti version is 0.8.8a.

Installing Cacti
Your Linux distribution probably includes a ready-to-install Cacti package. PHP and MySQL should be already installed and working. If they are not working properly, the setting up of Cacti will not finish.
The following steps are required to set up Cacti:
1    Ensure that the date.timezone variable has been defined inside the php.ini file (mine is /etc/php.ini) in order to avoid several warning messages during installation. Check it using the following command:

$ grep -i TimeZone /etc/php.ini
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
;date.timezone =
date.timezone = "Europe/Athens"

2    The next step is to create a Cacti MySQL user (called cacti by me) as well as a Cacti database (also called cacti by me). I used the following commands:

mysql> create database cacti;
Query OK, 1 row affected (0.04 sec)

mysql> CREATE USER 'cacti'@'localhost' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.06 sec)
mysql> grant CREATE, INSERT, SELECT, DELETE, UPDATE on cacti.* to cacti@localhost;
Query OK, 0 rows affected (0.02 sec)
mysql> grant CREATE, INSERT, SELECT, DELETE, UPDATE on cacti.* to cacti;
Query OK, 0 rows affected (0.00 sec)

3    Import the Cacti database (included in a file called cacti.sql that is provided by Cacti) using the following command:

$ sudo cat cacti.sql | mysql5 -u root –p cacti

4    You can check if the required Cacti tables were created by using the following MySQL commands:

mysql> use Cacti;
mysql> show tables;

5    Edit file cacti/include/config.php and update it with your MySQL related information. Mine is as follows:

/* make sure these values reflect your actual database/host/

user/password */
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "127.0.0.1";
$database_username = "cacti";
$database_password = "password";

6    Ensure Apache has access to and knows about the Cacti directory.
For the first task, both the user and group owners of the Cacti directory may need to be changed using the chown command. The user and the group of the Web server process should own the Cacti directory. For the second task, the Cacti directory should either be added inside the root directory of your Web server (defined by the DocumentRoot variable) or httpd.conf should know about it (using the Alias command).

7    Before setting up Cacti’s Poller to run as a cron job, it must be run manually as follows and the output watched for possible error messages:

$ sudo -u www /usr/bin/php cacti/poller.php

06/28/2012 11:56:07 AM - POLLER: Poller[0] WARNING: Cron is out of sync with the Poller Interval!  The Poller Interval is ‘300' seconds, with a maximum of a ‘300' second Cron, but 1656 seconds have passed since the last poll!

06/28/2012 11:56:08 AM - SYSTEM STATS: Time:0.1121 Method:cmd.php Processes:1 Threads:N/A Hosts:2 HostsPerProcess:2 DataSources:0 RRDsProcessed:0   

8    If everything is OK, Poller should be added to cron in order to run automatically. I needed to put it in the www user’s crontab because, on my machine, Apache runs as a process that is owned by the www user. You can do it as follows:

$ sudo -u www crontab –e
*/5 * * * * /usr/bin/php /opt/local/share/cacti/poller.php > /dev/null 2>&1

Installation is over and done with but, as you can see, the installation of Cacti is a little tricky; so you should be very careful during the process.

Configuring Cacti
Now it is time to configure Cacti. I opened the URL http://localhost/cacti/install/index.php. The default password is admin/admin. When asked, I used the following information (change the full path of your commands if needed):

snmpwalk path: /usr/bin/snmpwalk
snmpget path: /usr/bin/snmpget
RRDtool path: /opt/local/bin/rrdtool
PHP binary path: /usr/bin/php

When asked for the type of installation, select ‘New Install’ and click ‘Next >>’. Correct the path of the RRDTool, do not change any other value, check that the PHP executable path is correct and click ‘Finish’. You are now ready to use Cacti via the URL  http://localhost/cacti/index.php. The first thing Cacti asks you to do is to change the password for the admin user. After successfully setting the new password, you will see Cacti’s console tab

Running Cacti
After installing and configuring Cacti, you are ready to add devices and graphs to it. Feel free to view the cacti.log file, which (for my installation) is located inside /opt/local/share/cacti/log for error messages.

Monitoring a Cisco 877W router
What you need to know in advance in order to monitor your Cisco router with Cacti is the name of the SNMP community (CactiCom), and the hostname or the IP address of the router (cisco).
The steps for adding the Cisco router are the following:
Select ‘Devices’ on the left.
Select Type: ‘Cisco Router’and Status ‘Enabled’ and then click ‘Add’.

The most important fields are the Hostname (‘cisco’ in my case), the SNMP Community string (‘CactiCom’ in my case), and the SNMP Version in which you will have to select ‘Version 2’. Then click ‘Create’.

On the next screen, you will have to press the ‘Create Graphs for this Host’ on the upper right side. You will then see Figure 3. This figure lists all the available Cisco interfaces for this particular router. What interests us is Interface No 14 (Dialer1), which is the ADSL Internet connection interface. The desired graph type should be ‘In/Out Bytes’.
Select your interface of choice and click the ‘Create’ button. Another interesting interface is Number 5 (Dot11Radio0), which is Cisco’s Wi-Fi interface.

Then, select ‘Graph Threes’ from the left menu and click ‘Add’. Select the options that you can see in Figure 4. Then click ‘Create’.
Select the ‘Graphs’ tab and then, from the ‘Default Tree’, select the desired host. You will have to wait a little, until some data is obtained for the graph to be created. You will see something similar to Figure 5, as the graph will take a little while to get populated. If you click on the graph, you will get daily, weekly, monthly and yearly graphs.

The ‘Graph’ tab is the key screen for end users to view the graphs for their devices and to change settings.
Cacti is a very capable tool but in order to harness its power you need to experiment with it. An easier tool to configure is MRTG, but it has less capabilities.
Cacti also allows you to use existing plug-ins or create your own. Plug-ins allow developers to generate additional Cacti features without changing Cacti’s source code. I strongly recommend learning both Cacti and MRTG in order to use the right tool for the right job.

Web links and bibliography
[1]     Cacti: http://www.cacti.net/
[2]    Cisco MIBs: http://www.cisco.com/public/sw-center/netmgmt/cmtk/mibs.shtml
[3]    SNMP RFCs: http://www.snmp.com/protocol/snmp_rfcs.shtml
[4]    RRDtool: http://oss.oetiker.ch/rrdtool/
[5]    MRTG: http://oss.oetiker.ch/mrtg/
[6]    Cacti plug-ins: http://docs.cacti.net/plugins

LEAVE A REPLY

Please enter your comment!
Please enter your name here