10 min read

Cacti 0.8 Beginner’s Guide

Cacti 0.8 Beginner's Guide

Learn Cacti and design a robust Network Operations Center    

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:rrdtoolrrdtool.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.0lfn"

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.0lfn"

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 Thresholdn. 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 Thresholdn" 
AREA:isGreen#00FF00:"Interface eth0" 
GPRINT:intspeed:LAST:"Current:%8.0lf" 
GPRINT:intspeed:AVERAGE:"Average:%8.0lf" 
GPRINT:intspeed:MAX:"Maximum:%8.0lfn"

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.

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here