Cacti: Using Graphs to Monitor Networks and Devices

Exclusive offer: get 50% off this eBook here
Cacti 0.8 Beginner's Guide

Cacti 0.8 Beginner's Guide — Save 50%

Learn Cacti and design a robust Network Operations Center

£16.99    £8.50
by Thomas Urban | March 2011 | Networking & Telephony Open Source

This article will show you how to add new devices and how to add some performance measurement graphs to them. You will also learn how to group devices using the Cacti tree.

In this article by Thomas Urban, author of Cacti 0.8 Beginner’s Guide, we will cover the following topics:

  • Introduction to graph creation with RRDtool
  • Adding devices to Cacti
  • Adding graphs to a device
  • Assigning host templates to a device
  • Adding a device to the Cacti tree

 

Cacti 0.8 Beginner's Guide

Cacti 0.8 Beginner's Guide

Learn Cacti and design a robust Network Operations Center

        Read more about this book      

(For more resources on Network Monitoring, see here.)

An introduction to Cacti graphs and the RRDtool

You'll be looking into the actual graph creation process and what features Cacti supports.

Creating graphs with the RRDtool

Cacti uses the RRDtool to store the polled data. In addition to just storing the data, the RRDtool is also used to create the actual performance graphs.

If you now expect to see a fully-featured charting application, you will be disappointed. The RRDtool graph functionality offers only a very limited range of chart types. They can either be line charts, area charts, or a combination of both. There is no 3D option available, nor are there any other types of charts such as Pie or Scatter charts. This may be a disadvantage for some at first, but concentrating on only a few basic chart types makes it a fast specialized rendering engine for these. Being fast in displaying the raw RRD data is the main focus of the RRDtool graphing engine.

There are several graphing features available for plotting the data. The most commonly used types are:

  • LINE: The data is drawn as a line which can be formatted by width and type (for example, dashed line)
  • VRULE: A fixed vertical line is drawn at a defined value
  • HRULE: A fixed horizontal line is drawn at a predefined value (for example, threshold limits)
  • AREA: A solid filled area chart is drawn. Several area charts can be stacked together

Each of these graph types can be combined together to build the final chart image.

Let us dive into the graph creation process here to get a better understanding of the RRDtool graphing capabilities.

You need to have the RRDtool in your path for the following commands to work.

Basic RRDtool graph creation

Let's begin with the RRD example and use that RRD file as the basis for our graphs.

A note for Windows users
The following examples also work for Windows. Simply replace the RRDtool command with the full path to the RRDtool binary, for example, use
C:\rrdtool\rrdtool.exe instead of rrdtool.
You will also have to copy the DejaVu font from the RRDtool directory to your Windows fonts directory.

I have created a Perl script which will help in the creation of the RRD file and its automatic update with random data. In order to create the test RRD file, use the following command:

perl create_rrdfile_linux.pl test.rrd

If you have installed the RRDtool to C:\rrdtool you can use the following command for Windows:

perl create_rrdfile_windows.pl test.rrd

Having created the test data, you can now start to generate your first RRDtool-based graph. It is going to be a very simple graph displaying only the pure data.

Execute the following code at the command line interface (CLI):

rrdtool graph data_image.png \
--start 1282413600 \
--end 1282468500 \
DEF:intspeed=test.rrd:data:AVERAGE \
LINE2:intspeed#FF0000

This will create the following graph:

Cacti 0.8 Beginner’s Guide

So what does this command actually do? Using the command, you defined a start and end time in the Unix time format and defined the RRD file and data set you wanted to plot. You also told RRDtool to draw a two-pixel line (LINE2) using this data set and stored the resulting graph as data_image.png. The RRDtool automatically creates the X- and Y-axis for you and also inserts the time and value description. This is the most basic way of creating an RRDtool-based graph.

Advanced RRDtool graph creation

Although this basic graph image already has a lot of information in it, it is still missing some important features. It neither describes what is being graphed, nor does it provide additional information such as threshold breaches or MAX/MIN values. So, let's go back to this basic graph and look at how you can enhance it step-by-step using some of the advanced RRDtool features.

Adding a label and title to the graph

The first enhancement to our graph will be the addition of a label and a graph title. For this you can use the --vertical-label and --title parameters:

rrdtool graph data_image.png \
--start 1282413600 \
--end 1282468500 \
--vertical-label bps \
--title "Interface Speed" \
DEF:intspeed=test.rrd:data:AVERAGE \
LINE2:intspeed#FF0000

The resulting graph now has a title at the top and a description to the left as can be seen in the following image:

Cacti 0.8 Beginner’s Guide

As you can see, the RRDtool command added a rotated description to the Y-axis and also added the title at the top of the graph. The graph is now bigger in dimensions than the first one. The RRDtool uses only the width and height information to set the actual chart size. Everything else must be added to the graph separately. You can see more about how this works in the following examples.

Adding a legend to the graph

Now that you have added some description to the graph, you can also add a legend to it. For this, you are going to use the LAST, AVERAGE, and MAX poller values. The function of the GPRINT item is to add additional graph information to the legend. You are also going to add a description field to the LINE2 item. Adding a description to the LINE or AREA items will automatically create a legend entry for you.

The LAST, AVERAGE, and MAX values are always calculated using the data limited by the start and end time. Therefore they directly relate to the chart being displayed.

Let's look at the following command:

rrdtool graph data_image.png --start 1282413600 --end 1282468500 \
--vertical-label bps --title "Interface Speed" \
DEF:intspeed=test.rrd:data:AVERAGE \
LINE2:intspeed#FF0000:"Interface eth0" \
GPRINT:intspeed:LAST:"Current\:%8.0lf" \
GPRINT:intspeed:AVERAGE:"Average\:%8.0lf" \
GPRINT:intspeed:MAX:"Maximum\:%8.0lf\n"

The resulting image now also contains a small legend at the bottom:

Cacti 0.8 Beginner’s Guide

As you can see, the legend was added to the bottom of the graph, expanding its height. By adding a description to the LINE2 line (Interface eth0) the description was automatically placed at the bottom along with the color being used to draw that line. The GPRINT text and values have then been added right after the description. If you want to add some more text to the next line, you need to make sure that the last GPRINT value contains a \n (newline) string at the end.

In this example, you can also see that the RRDtool did not increase the width of the graph to fit the legend in it. The Maximum value has been silently dropped. GPRINT statements do not automatically increase the graph width, so you will need to increase the width yourself. This can be done by using the –width parameter.

Adding a threshold line to the graph

Now let's also set a threshold and display a line on the graph marking the threshold. This can be achieved by using the HRULE item. You are going to set a threshold at 50 and use a light grey color to display it on the graph. The following command creates this line and also adds an additional entry to the legend. In addition, you are also going to change the LINE2 item to an AREA item, so the data being displayed is shown as a filled area:

rrdtool graph data_image.png --start 1282413600 --end 1282468500 \
--vertical-label bps --title "Interface Speed" \
DEF:intspeed=test.rrd:data:AVERAGE \
HRULE:50#C0C0C0FF:"Threshold ( 50 )\n" \
AREA:intspeed#FF0000:"Interface eth0" \
GPRINT:intspeed:LAST:"Current\:%8.0lf" \
GPRINT:intspeed:AVERAGE:"Average\:%8.0lf" \
GPRINT:intspeed:MAX:"Maximum\:%8.0lf\n"

You can see the light gray line being printed horizontally in the image, providing a good overview of when the data exceeds the threshold:

Cacti 0.8 Beginner’s Guide

Note the usage of the newline string \n in the description string for the HRULE item. As you can see in the graph, the following text items are added to the next line.

Adding threshold breaches to the graph

You have now seen how you can add a threshold line to the graph, but you probably also want to change the color of the data every time the threshold is breached. Let us assume that you want to have the color go red at or above the threshold and go green once it is below. This can be achieved by using a Computed DEFinition (CDEF) and the LIMIT statement.

You define a CDEF named isGreen which returns a number as long as the value of intspeed is between 0 and 50, otherwise no value is returned. You are going to use this CDEF to change the color of the displayed area.

Instead of using the intspeed value you assign this new CDEF isGreen to the AREA item and change the color of the AREA to green (RGB: 00FF00). You also create a new AREA entry, to which you now assign the intspeed value, set the color to red, and give it a description Over Threshold\n. For this to work correctly, you need to place this new AREA above the old AREA statement.

Why are there two AREA statements? In fact, changing the color of one AREA as it is displayed is not possible, so you need to do a little trick here. The first AREA statement will graph all values in red, also the ones which are below the threshold, as you have seen in the preceding example. With the second AREA statement a green area will be drawn at all data values which are below the threshold. As the color is not transparent, the red area will disappear. You can see the total red area when you remove the second AREA statement.

The complete code now looks like the following:

rrdtool graph data_image.png --start 1282413600 --end 1282468500 \
--vertical-label bps --title "Interface Speed" \
DEF:intspeed=test.rrd:data:AVERAGE \
CDEF:isGreen=intspeed,0,50,LIMIT \
HRULE:50#C0C0C0FF:"Threshold ( 50 )\n" \
AREA:intspeed#FF0000:"Over Threshold\n" \
AREA:isGreen#00FF00:"Interface eth0" \
GPRINT:intspeed:LAST:"Current\:%8.0lf" \
GPRINT:intspeed:AVERAGE:"Average\:%8.0lf" \
GPRINT:intspeed:MAX:"Maximum\:%8.0lf\n"

Run this code from the command line and you will see the resulting graph:

Cacti 0.8 Beginner’s Guide

All of the graphs you have just created can be created in Cacti using the Cacti web interface. This section provides a small and very limited overview of the capabilities of the RRDtool graphing functions, but should give you enough ideas to start playing around with it to create your own graphs.

Adding devices to Cacti

A device in Cacti can be anything which can be monitored remotely or locally. This can include storage devices, Windows or UNIX servers, and of course network devices. For Cacti to be able to monitor a device, it needs to be reachable by ping or SNMP, but the actual data retrieval can also be done using scripts and commands, or a set of SNMP queries.

Creating a device

Creating a device in Cacti can be achieved by using the Cacti web interface. You are going to add your first device here. While looking at the different steps it takes to add a device, you are not going too much into the details of every field, as most of the user interface is self-explanatory and provides a detailed description of each field.

Before you start: Create a naming standard
If you have not already done so, you should now think about a naming standard for your devices. Creating and keeping to a naming standard is the first step to automation.

 

Cacti 0.8 Beginner's Guide Learn Cacti and design a robust Network Operations Center
Published: March 2011
eBook Price: £16.99
Book Price: £27.99
See more
Select your format and quantity:

 

        Read more about this book      

(For more resources on Network Monitoring, see here.)

Time for action – creating a new device in Cacti

  1. Login as an admin user to your new Cacti installation.
  2. Click on the Devices link under the Management menu. This will open a table with all devices added so far. For a new installation there should only be the localhost device showing its status as Up.
  3. On the top right of the new page click on Add. This is the default position for this Add link.

    (Move the mouse over the image to enlarge.)

  4. You will now be presented with the Devices [new] screen. Have a look at this screen and make yourself comfortable with the different fields.
  5. Enter a Description and Hostname (or IP address).
  6. If you add an SNMP-enabled device, select SNMP as the Downed Device Detection method. Otherwise select Ping. When selecting Ping you can choose the protocol type and port to use.

    Cacti 0.8 Beginner’s Guide

  7. Enter the SNMP community and select the correct version (some additional fields will show up when you choose SNMP Version 3). If the device is not SNMP compatible, you can select Not used.
  8. You can also add some notes. Click on the Create button once you are finished.

What just happened?

You just created your first device within Cacti by providing some basic information such as an IP address and SNMP management options. With this information Cacti is now able to poll the device. However, it still does not have any graphs associated with it.

Selecting host templates for the device

You may have noticed the Host Templates field, but what is a host template? A host template is a predefined package of graphs or data queries which can be assigned to a device. Using a template for complex devices reduces the administrative task for adding devices. Here you are going to assign a template to the device. Host templates can also be selected once the device has been created. Cacti comes with some very basic host templates such as Cisco Router Windows 2000/XP Host or Generic SNMP-enabled Host. All of these contain predefined graphs or data queries for these hosts.

Time for action – adding a host template to the device

  1. Go back to the device overview page by clicking on the Devices link under the Management menu.
  2. Click on the device (the description) you have just created.
  3. In the Host Template drop-down box, select a template that fits your device best.
  4. Click on the Save button.
  5. Note the additional entries in the Associated Graph Templates and Associated Data Queries fields.

What just happened?

By selecting a host template for the device, you have added a predefined package of graph templates and data queries to the host. This is a convenient way of reducing the administrative tasks of adding these manually through the provided drop-down lists.

Adding graphs to the device

Cacti displays performance data as graphs, therefore we are now going to add some basic graphs to the device which we have just added. The first graph which you are going to add is a simple ping graph. Let's go ahead and add the ping template to the host and later add the associated graph to the device.

Time for action – adding graphs to the device

  1. Go back to the device overview page by clicking on the Devices link under the Management menu.
  2. Click on the device you have just created.
  3. In the Associated Graph Templates section select the Unix - Ping Latency from the drop-down list and click on the Add button.

  4. Click on the Save button at the bottom of the page.
  5. Go to the top of the page and click on, Create Graphs for this Host.
  6. Select Create: Unix - Ping Latency.

  7. Click on the Create button.
  8. A new screen will appear, where you can choose a legend color and text, but for now, just click on Create.
  9. You will be redirected back to the graphs selection screen with the entry we selected being greyed out.

    Cacti 0.8 Beginner’s Guide

What just happened?

You just added your first graph to a Cacti device by adding a graph template to the device and selecting it during the graph creation screen. Cacti will now start to poll the data for this graph and generate the associated RRD file for it.

The Unix templates
Except for the Ping Latency template, all other Unix templates are for the localhost only and will not provide any information for remote systems.

Adding interface graphs to a device

Adding interface graphs is a little different from adding a generic one such as the ping graph. Normal network devices have several network interfaces, all of which can be polled for performance data. Cacti provides a nice interface for selecting the different network interfaces using the web interface. In the following section you are going to look into this kind of graph selection.

Time for action – adding interface graphs to a device

  1. Go back to the device overview page by clicking on the Devices link under the Management menu.
  2. Click on the device you have just created or create any other SNMP capable device having network interfaces.
  3. Configure the device to use SNMP and click on the Save or Create button.

  4. Make sure that the following information appears at the top of the page. This will show that the device is SNMP capable.

  5. In the Associated Data Queries section select the SNMP – Interface Statistics from the drop-down list and click on the Add button. If it is already there, then skip this step.

  6. Click on the Save button at the bottom of the page.
  7. Go to the top of the page and click on Create Graphs for this Host.
  8. On the new page which appears, select the interfaces you want to monitor and select a Graph type from the drop-down list.
  9. Click on the Create button.

What just happened?

You added the SNMP – Interface data query to the device and selected some interfaces from the interfaces list.

The SNMP – Interface data query is a special package, containing the graph definitions and a kind of blue-print for Cacti to poll information for the interfaces of a device.

Adding devices to the Cacti tree

The Cacti tree lists sub-trees, hosts, and graphs in a tree-like interface. It is the main user interface for the Graphs tab. There can be more than one tree which allows for a granular definition of the tree structure.

Before creating the Cacti tree, think about a good structure for it. Changing the tree later is going to involve quite some manual work, so it is better to have this set up correctly beforehand, so it is better to have this set up correctly beforehand.

Creating a tree

Cacti already has a default tree defined which holds the localhost. You are going to leave this default tree empty and create your very own tree.

Time for action – creating a Cacti tree

  1. Click on Graph Trees under the Management menu.
  2. You will see the Default Tree. Click on the Add link to the top right of that table.
  3. Enter a name, for example, Customer A.
  4. Click on the Create button.

Cacti 0.8 Beginner’s Guide

What just happened?

You created a new Cacti Tree called Customer A which you can now use to add all Customer A-specific entries. Using separate trees for customers or business units will enable you to better allow or deny access to these for specific users.

Sub-tree items

A sub-tree item enables the creation of sub-entries to the Cacti tree. These can be entries such as "Country", "Site", or a "Business Unit". Creating sub-tree items allows end users to easily find their devices on the Cacti Tree.

Time for action – adding a sub-tree

  1. Click on Add at the top right of the Tree Items table.
  2. Select Header as the Tree Item Type.
  3. Enter Country A as the title.
  4. Click on the Create button.
  5. Click on the (Add) link next to the new Country A entry.
  6. Keep the Parent Item to Country A and the Tree Item Type to Header.
  7. Enter Site A as the title.
  8. Click on the Create button.

Cacti 0.8 Beginner’s Guide

What just happened?

You created your first site for Customer A. You can now use this tree to fit all countries, sites, and buildings into a nice manageable tree structure. Your end users will immediately recognize the structure and will be able to quickly find the necessary information.

Adding a device to the tree

Now that you have created a tree and its sub-tree items, you can move on and add a device to the tree.

Time for action – adding a device to the Cacti tree

  1. Click on the (Add) link next to the Site A entry.
  2. Select Host as Tree Item Type.
  3. From the Host drop-down list, select the host which you created earlier. There should also be a Localhost listed. This is the Cacti server.
  4. Leave all the others to their defaults.
  5. Click on the Create button.

Cacti 0.8 Beginner’s Guide

What just happened?

You just added your first device to your newly created Cacti tree. You can also add single graphs to the tree by changing the Tree Item type.

Summary

In this article you have learned quite a bit about the RRDtool graph generation features. Specifically you have covered the following:

  • Creating some basic graphs using the RRDtool
  • Adding advanced features such as threshold line and color changes based on the threshold
  • Adding a device to Cacti
  • Assigning graphs and interface graphs to a device
  • Creating a new Cacti tree containing sub-tree items and devices

Further resources on this subject:


Cacti 0.8 Beginner's Guide Learn Cacti and design a robust Network Operations Center
Published: March 2011
eBook Price: £16.99
Book Price: £27.99
See more
Select your format and quantity:

About the Author :


Thomas Urban

Thomas Urban is currently employed as Senior Systems and Network Engineer in the valve industry. He is also the founder of Urban-Software.de, a small consulting company that provides services and software for Cacti.

He had his first experience with Cacti when working in the Strategic Outsourcing business at IBM Germany where he introduced Cacti to several external customers.

Books From Packt


Cacti 0.8 Network Monitoring
Cacti 0.8 Network Monitoring

Tcl 8.5 Network Programming
Tcl 8.5 Network Programming

MySQL 5.1 Plugin Development
MySQL 5.1 Plugin Development

OpenVPN 2 Cookbook
OpenVPN 2 Cookbook

Zabbix 1.8 Network Monitoring
Zabbix 1.8 Network Monitoring

FreePBX 2.5 Powerful Telephony Solutions
FreePBX 2.5 Powerful Telephony Solutions

Asterisk 1.4 – the Professional’s Guide
Asterisk 1.4 – the Professional’s Guide

FreeSWITCH 1.0.6
FreeSWITCH 1.0.6


Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software