You are on page 1of 11

Deploying Cacti and PHP Weathermap

Project owners: Kristina Groth Sven Jonsson Peter Sjdin

Coaches: Siraj Rathore Voravit Tanyingyong

Experts: Ola Gran Robert Olsson Bjrn Pehrson Bernt Sundstrm

Team members: Axel Fant Eldh Ruslan Mukhammadov Victor Tsarinenko Nikolaos Roumpoutsos Denys Knertser Ioannis Sapountzis Razvan Popescu axelfe@kth.se ruslanm@kth.se victorts@kth.se nikosr@kth.se denys@kth.se ioanniss@kth.se razvanp@kth.se

CareNet 2012, Deploying Cacti and PHP Weathermap | Victor Tsarinenko, victorts@kth.se

1 of 11

Contents
Contact .............................................................................................................................................................................. 3 Purpose of this document ..................................................................................................................................... 3 Revision history........................................................................................................................................................... 3 Intro .................................................................................................................................................................................... 4 Installing Cacti .............................................................................................................................................................. 4 Installing Cacti plugin architecture ............................................................................................................ 5 Installing the Weathermap plugin............................................................................................................... 6 Making it all work together ............................................................................................................................. 6 Adding devices, graphs, maps............................................................................................................................. 9 Summary....................................................................................................................................................................... 10 References ................................................................................................................................................................... 11

CareNet 2012, Deploying Cacti and PHP Weathermap | Victor Tsarinenko, victorts@kth.se

2 of 11

Contact Name: Victor Tsarinenko Email: victorts@kth.se Purpose of this document This document describes the installation procedure of Cacti - network graphing system, and steps required to configure and run it together with PHP Weathermap plugin which helps with network visualization. Revision history Version 1.0 Original document December 8, 2012

CareNet 2012, Deploying Cacti and PHP Weathermap | Victor Tsarinenko, victorts@kth.se

3 of 11

Intro
Cacti provides means of collecting network statistics and representing this data on graphs. [1] Cacti is based on the RRDTool [2] for collecting and storing the data. Within CareNet project Cacti is used mainly to collect and store statistics of the router interfaces and the average load on the routers. Power monitoring solution for Residential Gateways [3] is also based on Cacti. The Weathermap plugin is used to create visual map of the core CareNet network. [4]

Installing Cacti
Installation of Cacti under Ubuntu server 12.04 x64 is pretty straightforward; however, in order for the Weathermap plugin to work one will need to install Cacti plugin architecture. Plugin architecture enables support for various plugins developed for Cacti. If you dont like the idea of installing Plugin architectures manually you can follow the Easy install how-to from Cacti forums, which describes how to add the specific repositories containing the package. [5] This report will describe manual installation of Cacti plugin architecture. To install cacti run:
# apt-get update # apt-get install cacti

This will install Cacti v.0.8.7h (the version available at the time of writing this document) together with the required packages, including MySQL, PHP, Apache (or another web server), and several libraries. The install will require some space on the hard drive so make sure to run your installation on a host with enough space. During the installation you will be asked to set the root password for MySQL, make sure to use strong passwords. A warning message regarding the incorrect path for the adodb php library may pop up; we will correct the path later manually. If you already run Apache on your host then the choice for the web server is obvious, however, if you want to use another web server you can do so, for our install we use Apache. Use dbconfig to configure the database unless you really know what you are doing. At the final step of the installation you will have to create a database for cacti: type the root password you created in earlier, and then create a password for the cacti database. The configuration file for these parameters will be then located at /usr/share/cacti/site/include/config.php . Cacti installation at the OS level is finished now, you can proceed to running the web based Cacti setup script, which will configure the web user interface and setup database connection; but if you want to run the plugin architecture, install it before proceeding to web based setup.

CareNet 2012, Deploying Cacti and PHP Weathermap | Victor Tsarinenko, victorts@kth.se

4 of 11

Installing Cacti plugin architecture Download the latest plugin architecture from http://www.cacti.net/downloads/pia/. The version used for the project is 0.8.7h:
# wget http://www.cacti.net/downloads/pia/cacti-plugin-0.8.7h-PA-v3.0.tar.gz

Untar the archive:


# tar xzf cacti-plugin-0.8.7h-PA-v3.0.tar.gz # cd cacti-plugin-arch/

Now copy the contents of the files/ directory, the patch, and the pa.sql file from the archive to the directory with Cacti installed:
# # # # cp cp cp cd -r files/* /usr/share/cacti/site/ cacti-plugin-0.8.7h-PA-v3.0.diff /usr/share/cacti/site/ pa.sql /usr/share/cacti/site/ /usr/share/cacti/site

Apply the patch:


# patch -p1 -N < cacti-plugin-0.8.7h-PA-v3.0.diff

Add the database changes:


# mysql -u cacti -p cacti < pa.sql

Here, -u specifies the username for the database, which is cacti in our case, -p key instructs mysql utility to prompt for the password, and cacti is the database name. Next correct the paths in Cacti configuration file:
# nano include/global.php # change the URL-path: # $url_path = ; # to $url_path = /cacti/; # rra files path: # change $config["rra_path"] = $config["base_path"] . /rra; # to $config["rra_path"] = /var/lib/cacti/rra; # change the adodb module path: # include_once($config["library_path"] . /adodb/adodb.inc.php); # to include_once(/usr/share/php/adodb/adodb.inc.php);

CareNet 2012, Deploying Cacti and PHP Weathermap | Victor Tsarinenko, victorts@kth.se

5 of 11

Installing the Weathermap plugin Tell Cacti to enable the plugin architecture and weathermap plugin (the plugin will be installed during the next step) by adding the following lines to config.php file:
# nano include/config.php $plugins = array(); $plugins[] = 'weathermap';

Once the plugin architecture is enabled, proceed with installation of the actual plugins. To install the Weathermap plugin download the package from http://www.networkweathermap.com/download:
# cd # wget http://www.network-weathermap.com/files/php-weathermap-0.97a.zip

Install the unzip utility (for the sake of simplicity):


# apt-get install unzip

Unzip and copy the plugin to /usr/share/cacti/site/plugins:


# unzip php-weathermap-0.97a.zip # cp -r weathermap /usr/share/cacti/site/plugins

Making it all work together Now, it is time to run the Cacti web based setup. Go to http://yoursite/cacti. Most probably you will see the following message:
# FATAL: Cannot connect to MySQL server on 'localhost'. Please make sure you have specified a valid MySQL database name in 'include/config.php'

This is due to the incorrect username and password settings in the config.php file (will most likely appear after patching and installing plugin architectur e). To correct the issue perform the following:
# # # # # cd /usr/share/cacti/site nano include/config.php supply the correct values you used during the setup here: $database_username = "cacti"; $database_password = "cacti";

Now, the http://yoursite/cacti should point to the first run setup dialog or Cacti Installation Guide. Go ahead and click Next. Choose the New Install at the next screen. The setup will check if you have all the necessary components for the system. Click Finish to deploy the configuration. The next screen is the standard login screen
CareNet 2012, Deploying Cacti and PHP Weathermap | Victor Tsarinenko, victorts@kth.se 6 of 11

for the system. The default username:password pair is admin:admin. Cacti will prompt you to change the default password right after you log in. You should see three tabs in the web interface, namely: console, graphs, and weathermap. Go to console -> user management -> admin and enable all the permissions for the admin user if some of the permissions are missing. Also go to http://yoursite/cacti/plugins/weathermap/check.php to check if all the necessary libraries are installed. Most probably you will need to install the php5 -gd:
# apt-get install php5-gd

Restart the Apache server for the changes to take effect:


# service apache2 restart

Check the http://yoursite/cacti/plugins/weathermap/check.php again. You will need a couple of additional tweaks to get the most out of the weathermap plugin. Set the permissions for the www-data user on the plugins/weathermap/output directory so that Cacti poller process can write to it (basically the permissions must be the same as the permissions for the rra directory):
# chown www-data plugins/weathermap/output/

Make sure the web server can write to the plugins/weathermap/configs directory:
# chown www-data plugins/weathermap/configs # chmod u+w plugins/weathermap/configs

By default web based editor used to create network maps is disabled. To enable it perform the following steps: change the flag in plugins/weathermap/editor.php :
# nano plugins/weathermap/editor.php # change $ENABLED=false; to $ENABLED=true;

CareNet 2012, Deploying Cacti and PHP Weathermap | Victor Tsarinenko, victorts@kth.se

7 of 11

Then enable access to the editor.php file in web server configuration:


# nano /etc/apache2/conf.d/cacti.conf # add the following: <Directory /var/www/html/cacti/plugins/weathermap> <Files editor.php> Order Deny,Allow Deny from all Allow from 127.0.0.1 </Files> </Directory>

Restart the Apache server for the changes to take effect:


# service apache2 restart

Now the editor should be accessible via web interface: weathermap tab -> editor or (http://yoursite/cacti/plugins/weathermap/editor.php). If you use the same versions of the packages as described in this guide, you will end up without required tables in the cacti database for the weatermap plugin. It has to be added manually. The easiest way is to create a file with the following content:
# nano weathermap.sql CREATE TABLE weathermap_maps ( id int(11) NOT NULL auto_increment, sortorder int(11) NOT NULL default 0, group_id int(11) NOT NULL default 1, active set('on','off') NOT NULL default 'on', configfile text NOT NULL, imagefile text NOT NULL, htmlfile text NOT NULL, titlecache text NOT NULL, filehash varchar (40) NOT NULL default '', warncount int(11) NOT NULL default 0, debug set('on','off','once') NOT NULL default 'off', runtime double NOT NULL default 0, lastrun datetime, config text NOT NULL default '', thumb_width int(11) NOT NULL default 0, thumb_height int(11) NOT NULL default 0, schedule varchar(32) NOT NULL default '*', archiving set('on','off') NOT NULL default 'off', PRIMARY KEY (id) ) ENGINE=MyISAM; CREATE TABLE weathermap_auth ( userid mediumint(9) NOT NULL default '0', mapid int(11) NOT NULL default '0' ) ENGINE=MyISAM;

CareNet 2012, Deploying Cacti and PHP Weathermap | Victor Tsarinenko, victorts@kth.se

8 of 11

CREATE TABLE

weathermap_groups ( `id` INT(11) NOT NULL auto_increment, `name` VARCHAR( 128 ) NOT NULL default '', `sortorder` INT(11) NOT NULL default 0, PRIMARY KEY (id) ) ENGINE=MyISAM;

INSERT INTO weathermap_groups (id,name,sortorder) VALUES (1,'Weathermaps',1); CREATE TABLE IF NOT EXISTS weathermap_data (id int(11) NOT NULL auto_increment, rrdfile varchar(255) NOT NULL,data_source_name varchar(19) NOT NULL, last_time int(11) NOT NULL,last_value varchar(255) NOT NULL, last_calc varchar(255) NOT NULL, sequence int(11) NOT NULL, local_data_id int(11) NOT NULL DEFAULT 0, PRIMARY KEY (id), KEY rrdfile (rrdfile), KEY local_data_id (local_data_id), KEY data_source_name (data_source_name) ) ENGINE=MyISAM;

Now use the same way as with the pa.sql to parse the file to mysql:
# mysql -u cacti -p cacti < weathermap.sql

The username here is cacti (specified by the -u option), -p option tells mysql to prompt for the password, and cacti is the database name. Now the whole system is ready to be utilized. Side note: If you want to export the map images created by the weathermap plugin add something like the following to your web server configuration:
# nano /etc/apache2/conf.d/cacti.conf <Directory /var/www/html/cacti/plugins/weathermap/output> AllowOverride None Order allow,deny Allow from all </Directory>

Adding devices, graphs, maps By default cacti supports SNMP for polling the devices. Within the context of the CareNet projects we use SNMP daemons on routers running Bifrost and collect the interface statistics, where SNMP proves very handy. To add a host to Cacti go to http://yoursite/cacti -> console -> devices -> add. Fill in the required data and set the correct community names if you are using SNMP for polling. You will be able to collect data from the interfaces once the SNMP check against the host is successful.

CareNet 2012, Deploying Cacti and PHP Weathermap | Victor Tsarinenko, victorts@kth.se

9 of 11

To create a graph go to console -> new graphs -> choose the host and a graph you want to create and click Create. To create a weathermap go to weathermap -> editor. After designing a map go to weathermap -> weathermap management -> add and select the maps you want to set active. The process of adding new maps, devices, graphs, etc is pretty self-explanatory, considering the web interface is used. Thus, these topics are slightly mentioned in the report. If you want to use custom data collection methods utilizing custom written scripts you can find some insights on the topic in the Power monitoring for Residential Gateways report. [3]

Summary
This report mainly focused on installing Cacti - The complete RRDTool-based Graphing solution in the context of the CareNet 2012 project. While the solo Cacti installation is trivial, making it work with PHP Weathermap plugin may sometimes turn to be a bit trickier. This report focused on how to make the solutions work together, and provided a step by step guide to deploy the system.

CareNet 2012, Deploying Cacti and PHP Weathermap | Victor Tsarinenko, victorts@kth.se

10 of 11

References
1 Cacti, The Complete RRDTool-based Graphing Solution, online, accessed Dec 8, 2012, available at http://www.cacti.net/. 2 RRDTool, RRDTool: Logging and Graphing, online, accessed Dec 8, 2012, available at http://oss.oetiker.ch/rrdtool/. 3 CareNet 2012, Power monitoring for residential gateways, online, accessed Dec 8. 2012, available at http://ttaportal.org/wpcontent/uploads/2012/11/PowerMonitoringforRGs.pdf. 4 CareNet 2012, CareNet core links status, online, accessed Dec 8, 2012, available at http://ttaportal.org/menu/projects/carenet/carenet-fall-2012/networkavailability/. 5 Cacti Forums, Easy install, online, accessed Dec 8, 2012, available at http://forums.cacti.net/viewtopic.php?f=6&t=48367.

CareNet 2012, Deploying Cacti and PHP Weathermap | Victor Tsarinenko, victorts@kth.se

11 of 11

You might also like