Newton Linux User Group Graphing SNMP with Cacti and RRDtool Summary: Cacti is an interface that can be used to easily manage the graphing of SNMP data. These graphs allow you to visualize performance trends within your Linux systems or network infrastructure. We have been using Cacti to manage RRD based graphs of our hosting network for quite some time now. When we considered moving from MRTG based graphing to RRDtool based graphing, it seemed that configuring RRDtool was going to be much more difficult than configuring MRTG had been. Cacti has made config and management of MANY data sources a breeze. I ll be demonstrating the following: * How to install and configure Cacti on a RedHat 9 system * How to graph cpu/memory/disk usage on a Linux system via SNMP. * How to graph network usage on a managed switch via SNMP You could also use Cacti to graph Windows system performance. We won t be covering this because the "L" in NLUG doesn t stand for Windows. :) Website References: Cacti: Web-based RRDtool Frontend http://raxnet.net/products/cacti/ RRDtool: a reimplementation of MRTGs graphing and logging features http://www.rrdtool.org/ System Requirements: Cacti Server Linux with Apache, MySQL 3.23+ and PHP 4.1+ RRDtool Net-SNMP (or Ucd-SNMP on older systems) Linux Hosts SNMP support (may need to install and config Net-SNMP or Ucd-SNMP) SNMP community string / password (you must have this) Network Hosts SNMP support (most routers and managed switches support SNMP) SNMP community string / password (you must have this) Datility Networks, Inc. 1 of 9 9/7/2004
Cacti Server Installation Notes: The demonstration server is running Linux Redhat 9 with current updates. We already have a working installation of Apache, MySQL, PHP and phpmyadmin 2.5.7. # Start by creating a cacti database as well as the cacti user via phpmyadmin... http://cacti-demo.newtonlug.org/phpmyadmin/ * CREATE NEW DATABASE: "cacti" * PRIVILEGES * ADD A NEW USER * USERNAME: cacti * HOSTNAME: localhost * PASSWORD: random*cacti*sql*password * GO * DATABASE SPECIFIC PRIVILEGES: cacti * SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, INDEX, DROP # We need to download and extract cacti. We ll download it to /opt/cacti/ directory. [root@cacti root]# cd /opt/ [root@cacti opt]# mkdir cacti/ [root@cacti opt]# cd cacti/ [root@cacti cacti]# wget http://www.raxnet.net/downloads/cacti/cacti-0.8.5.tar.gz [root@cacti cacti]# tar -zxvf cacti-0.8.5.tar.gz [root@cacti cacti]# mv cacti-0.8.5/ /var/www/html/cacti/ [root@cacti cacti]# cd /var/www/html/cacti/ # We need to populate our new cacti database with SQL information [root@cacti cacti]# mysql u root -p cacti < cacti.sql # We need to update the cacti configuration file to include our SQL database info [root@cacti cacti]# vi include/config.php $database_default = "cacti"; $database_hostname = "localhost"; $database_username = "cacti"; $database_password = "random*cacti*sql*password"; # We will create a cacti username and set a password on the account [root@cacti cacti]# useradd cacti [root@cacti cacti]# passwd cacti Changing password for user cacti. New UNIX password: random*cacti*user*password # We need to change ownership of the rra and log directories cacti will use. [root@cacti cacti]# chown -R cacti rra/ log/ # We need to add a line to crontab so we can collect data every 5 minutes [root@cacti cacti]# vi /etc/crontab */5 * * * * cacti php /var/www/html/cacti/cmd.php > /dev/null 2>&1 # If we run the command we just added to CRON, we should receive a message as follows. [root@cacti cacti]# php /var/www/html/cacti/cmd.php There are no items in your poller cache. Make sure you have at least one data source created. If you do, go to Utilities, and select Clear Poller Cache. time: 0 # A majority of this information is also available on the following webpage... http://www.raxnet.net/products/cacti/docs/install.htm # Cacti is now installed. We ll prepare our SNMP hosts and devices next. Datility Networks, Inc. 2 of 9 9/7/2004
Linux System - SNMP Installation and Configuration Notes: Before you can collect data from your Linux system, you must install and configure SNMP. We will demonstrate with a Linux Redhat 9 system. If you have an older linux system, you may need to substitute net-snmp with ucd-snmp. # Check to see if net-snmp (or ucd-snmp) is installed. If not, install it. [root@rh9 root]# rpm -qa grep -i snmp [root@rh9 root]# apt-get install net-snmp # Backup the SNMPd configuration and replace the config with the following... [root@rh9 root]# cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.orig [root@rh9 root]# vi /etc/snmp/snmpd.conf ## GENERIC SNMPD.CONF FILE ## com2sec notconfiguser default snmp*password group notconfiggroup v1 notconfiguser group notconfiggroup v2c notconfiguser view systemview included.1 access notconfiggroup "" any noauth exact systemview none none # System Location Information syslocation Unknown (edit /etc/snmp/snmpd.conf) syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf) # Check for loads: load 12 14 14 # Configure the SNMPd service to start on system boot [root@rh9 root]# chkconfig snmpd on # Start the SNMPd service immediately [root@rh9 root]# service snmpd start # Allow SNMP (161/udp) from the cacti server (192.168.111.4) and restart firewall [root@rh9 root]# vi /etc/sysconfig/iptables -A RH-Lokkit-0-50-INPUT -p udp -m udp -s 192.168.111.4 --dport 161 -d 0/0 -j ACCEPT [root@rh9 root]# service iptables restart Our Linux system is now configured to accept SNMP queries and respond to the queries if the correct community string (snmp*password) is provided. We will configure the cacti server to query SNMP on this linux system in just a moment. Disclaimer: This is only a sample configuration file that happens to allow monitoring of most available information via SNMP. If you are monitoring SNMP in a production environment, you should take time to customize the snmpd.conf file to meet your particular needs. Datility Networks, Inc. 3 of 9 9/7/2004
Hardware Device - SNMP Configuration Notes: Before you can collect data from your hardware device (ie: router or managed switch), you must enable and configure SNMP. We will demonstrate with an HP ProCurve switch. I ll connect my workstation to the switch using a console cable. Afterwards, I ll use my communication program to communicate with the switch via COM1. The port settings I used were 9600 bps, 8N1, and NO FLOW CONTROL. Next, I ll login to the switch via the console cable using my password. HP J3299A ProCurve Switch 224M Firmware revision D.05.14 Copyright (C) 1991-1998 Hewlett-Packard Co. All Rights Reserved. RESTRICTED RIGHTS LEGEND Use, duplication, or disclosure by the Government is subject to restrictions as set forth in subdivision (b) (3) (ii) of the Rights in Technical Data and Computer Software clause at 52.227-7013. HEWLETT-PACKARD COMPANY, 3000 Hanover St., Palo Alto, CA 94303 Password: my*switch*password Then I choose Switch Management and IP Configuration to set the IP address. Then I choose Switch Management and SNMP Community Names to set the password. HP ProCurve Switch 224M sw-nlug-demo 1-Jan-1990 0:07:54 ==========================- CONSOLE - MANAGER MODE -============================ Switch Management Access Configuration - SNMP Communities Community Name : snmp*password MIB View : Manager Write Access : Restricted Manager Address ---------------------- 192.168.111.4 Actions-> Cancel Edit Save Help Enter Community Name - up to 16 characters, case sensitive; no spaces Use arrow keys to change field selection, <Space> to toggle field choices, and <Enter> to go to Actions. Once an IP address and an SNMP community name have been configured on the managed hardware, we should be able to query the hardware and create graphs using cacti. Datility Networks, Inc. 4 of 9 9/7/2004
Cacti Server Configuration Notes: Now that we have several SNMP-enabled systems available, we can configure cacti so that it will graph them. Visit the cacti site to begin the configuration process. http://cacti-demo.newtonlug.org/cacti/ The first time you visit the site, you are presented with an informational welcome page similar to the following. Click NEXT. You will then be asked to choose the type of installation. Choose NEW INSTALL and click NEXT. You will then be presented with a list of dependencies. If all of the RPMs you will need are installed (including net-snmp, net-snmp-utils and rrdtool), cacti should be able to locate all of the dependencies. The demo server is running Linux Redhat 9 with current updates. We already have a working install of Apache, MySQL, PHP, etc. Correct dependencies as necessary or click FINISH. Datility Networks, Inc. 5 of 9 9/7/2004
After you have clicked FINISH, you will be presented with a login page. Login to your new cacti website with username admin and password admin. You will be required to change your password upon first login. First we ll setup graphs for our managed switch. Choose Devices under Management on the left-hand menu. Then add a device by clicking the Add link on the dark blue bar above the list of devices. We will enter the following information for the device. Description: sw-nlug-demo Hostname: 192.168.111.2 Host Template: Generic SNMP-enabled Host SNMP Community: snmp*password SNMP Version: Version 2 When you click CREATE, you will be taken to the device page. The page should show some basic SNMP Information just below the description and the hostname of the device. NOTE: If the page shows SNMP error, confirm the IP, be sure SNMP is enabled on the device and check any firewall rules that may be interfering with the query. Scroll down to the Associated Data Queries section near the bottom of the page and confirm that there is the data query called SNMP Interface Statistics was successfully queried. You may see something similar to the following: Scroll back to the top of the device page and click on the large blue link that says Create Graphs for this Host. You will be taken to a new page that should list the available SNMP data queries. We want to create graphs for all of the ports so we simply click on the checkmark in the upper-right corner of the Data Query area. This will mark all available ports. Next, click CREATE at the bottom of the page. Datility Networks, Inc. 6 of 9 9/7/2004
You will be presented with a list of indexes available for the graphs. Sometimes you have more than one option in the dropdown menu. These options influence the default names Cacti will give each of your graphs. We usually choose ifindex. Click CREATE to finish creating your graphs. That s it! Now you have graphs for your managed switch or other network device. Now let s setup graphs for our Linux system. Choose Devices under Management on the left-hand menu again. Then add a device by clicking the Add link on the dark blue bar above the list of devices. We will enter the following information for the device. Description: linux-nlug-demo Hostname: 192.168.111.5 Host Template: ucd/net SNMP Host SNMP Community: snmp*password SNMP Version: Version 2 When you click CREATE, you will be taken to the device page. The page should show some basic SNMP Information just below the description and the hostname of the device. NOTE: If the page shows SNMP error, confirm the IP, be sure SNMP is enabled on the device and check any firewall rules that may be interfering with the query. Scroll down to the Associated Data Queries section near the bottom of the page. You should see something similar to the following. Notice how the second query returned no items. Remove the ucd/net Get Monitored Partitions and add SNMP Get Mounted Partitions instead. Datility Networks, Inc. 7 of 9 9/7/2004
After making these changes, you should see data queries and graph templates similar to the following. Scroll back to the top of the device page and click on the large blue link that says Create Graphs for this Host. You will be taken to a new page that should list the available SNMP data queries. We want to create graphs for all of the available quries so we simply click on the checkmark in the upper-right corner of each Graph Template or Data Query area to mark all available queries. Next, click CREATE at the bottom of the page. Datility Networks, Inc. 8 of 9 9/7/2004
You will be presented with a list of indexes available for the graphs. Sometimes you have more than one option in the dropdown menu. These options influence the default names Cacti will give each of your graphs. We usually choose ifindex for Traffic graphs and hrstoragedescr for Storage Graphs. Click CREATE to finish creating your graphs. That s it! Now you have graphs for processor, memory, disk and traffic on your Linux system. Happy graphing! NOTE: Your graphs will always appear broken until the first 5 minute polling cycle has occurred. This is because the data files that the graphs are based on are not created until the first time the device is polled. Datility Networks, Inc. 9 of 9 9/7/2004