Lars Åges tanker

Politikk og teknologi

Automatic network graphing with Cacti

| 1 kommentar

I love graphs and statistics, and have used Cacti for some years for this. However, I’ve got a network that is larger than what can be set up manually in the GUI, and I often don’t have the time to update cacti whenever I setup a new switch, and forget it later. As such, it has to be automated.

What I do is set it up with the discovery-plugin for automatic discovery of all hosts on a network, and autocreate graphs for all interfaces. This is how I’ve done it.

Cacti installation

aptitude install snmp
cd /var/www
wget http://www.cacti.net/downloads/cacti-0.8.7d.tar.gz
tar zxfv cacti-0.8.7d.tar.gz
mv cacti-0.8.7d cacti && cd cacti

Get the latest version of cactiplugin from cactiusers.org:

wget http://mirror.cactiusers.org/downloads/plugins/cacti-plugin-0.8.7d-PA-v2.4.zip
unzip cacti-plugin-0.8.7d-PA-v2.4.zip
patch -p1 -N < cacti-plugin-0.8.7d-PA-v2.4.diff

If you get some rejected files, view what couldn’t be applied and edit those files manually. I got an error in include/global_constants.php and have to insert that part manually

Cacti Patch-install

Cacti Patch-install

The three lines marked with a + has to be inserted manually in include/global_contants.php around line 175 (just remember to not cut’n’ paste and include the + as I did once :P)

Edit include/global.php and change $database_default to your database name, $database_hostname, $database_username and$database_password to your database credentials.
Also, you need to change the path to the base of your cacti installation in $config[‘url_path’] to ‘/cacti/’;

mysql -u root -p
Password:
CREATE DATABASE cacti;
GRANT ALL PRIVILEGES ON cacti.* TO ‘cactiuser’@’localhost’ IDENTIFIED BY ‘cactiuser’;
source cacti.sql;

Go too http://your.server.address/cacti/ and complete the installation, and login as admin/admin. If everything looks OK, go back to your shell download discovery from cactiusers.org.

cd plugins
wget http://cactiusers.org/downloads/discovery.tar.gz
tar zxfv discovery-0.8.5.tar.gz
cd ../include

Edit global.php and around $plugins, add a new line for discovery:
$plugins[] = ‘discovery’;

And last, but not least; add poller.php to your crontab:
crontab -e
Add the line:

*/5 * * * * php /var/www/cacti/poller.php &>/dev/null

That should make your cacti-installation ready, and your hosts checked every 5 minutes.

Configuring Cacti Discovery


In Cacti, go to Settings -> Misc
Add your subnets to Subnet to scan, in my example, I run it against 10.0.4.0/25
Add your SNMP community name to SNMP Community. The first community you enter will be the first tested, so you should probably add your there, and have public as a backup and last.
I usually set Poller Frequency to once every week, but for testing, it might good to have it every 1 hour.

Rerun Data Queries should be set on, so that changes to your switches gets updated
Create Graphs for Up Interfaces Only is something you would have to find out yourself if you want. If you put it on, you will only graph interfaces that are actually up, and if you are mostly interested in your uplinks or haven’t got a lot of bandwidth to your switches, you should check it, but you want to know the bandwidth usage on your clients, you should leave it unchecked.

In the menu, go to Discovery Templates, and add a new template.

New hosts doesn’t automatically come into Cacti because Cacti needs to know what kind of device it is (server, switch, coffee-machine, etc.).
In the new template, select Host Template and choose Generic SNMP-enabled Host.
In SNMP Version, choose the SNMP-version in use on your network (I use version 1, as that works on most units).
In System Description, write something you expect to find in all your switches (I have all Ciscos in my network, so I’d expect to find «Cisco» in the description).

You should now get hosts showing up in your Device-list, after the time specified in Poller Frequency. However if you are like me, you are too lazy to wait an hour before the devices show up.
Instead, you can run the command to discover manually:
php plugins/discovery/findhosts.php -f -d

Changing graph names

When findhosts.php has run, you should have some automatically created graphs. However, they show up in the name of «host – Traffic – interface number»

Names of Cacti graphs after they are automatically created

Names of Cacti graphs after they are automatically created from findhosts

This really doesn’t help much, as I usually don’t know what’s on every port in my network. I do however know some of the ports, and have written what they are in the description of all ports that are uplinks or have servers/other special devices.

To change this, you can go to Data Queries -> SNMP – Interface Statistics -> In/Out Bits

Suggested Values are the prioritized list of names for graphs (name), and the graph title (title) displayed inside the graph.

Here you might have to experiment a little with what you want, but what I’ve used fits my equipment very good.

Graph names I use

Graph names I use

If one of the variables in the line is not set, that line will not be used, and the next line will be tested instead. You should experiment a little with how your own network does this. After changes in suggested values, you should run the command

php cli/poller_graphs_reapply_names.php -id=All

Én kommentar

  1. hello,
    just a few words to thank you for this document. You’re the first one I find who explains well how the cacti discovery plugin works !
    It helped me a lot.
    Kind regards,
    Cyril (France)

Legg igjen en kommentar

Påkrevde felter er merket *.