Chapter 11. Templates

Table of Contents
Graph Templates
Data Templates
Host Templates

Graph Templates

In Cacti, a graph template provides a skeleton for an actual graph. If you have many graphs that share most of their characteristics, using a graph template would probably make sense. After a graph is attached to a particular graph template, all changes made to the graph template will propagate out to all of its graphs.

Creating a Graph Template

To create a new graph template, select Graph Templates under the Templates heading and click Add.

The first thing you must do is give the template a name. This name has nothing to do with the graph title, but is what you will use to identify the template throughout Cacti. Second, you will notice a list of graph field names with Use Per-Graph Value checkboxes next to each one. The nice thing about templates in Cacti is that you can choose whether to template each field on a per-field basis. If you leave the checkbox uncheked, every graph attached to the template will inherit its value from the template. If the checkbox is checked, every graph attached to the template will contain its own value for that particular field.

Table 11-1. Field Description: Graph Templates

Name Description
Title

The title of the graph within Cacti and the title that will be printed on the actual graph itself.

Note: You can use the keyword |host_description| in this field, which will be automatically substituted with the current host description.

Image Format Choose whether you would prefer to output your graph images in PNG or GIF. According to the RRDTool graph manual PNG is preferred because it is both smaller and faster.
Height The height of the graph area in pixels
Width The width of the graph area in pixels
Auto Scale Enable auto scale for the graph. This option must be check to use the next two options. Upper/Lower limit values are ignored when using autoscale since these boundaries are determined automatically.
Auto Scale Options Choose whether you would like to use --alt-autoscale or --alt-autoscale-max on the graph. The RRDTool graph manual says: "Where --alt-autoscale will modify both the absolute maximum AND minimum values, this option will only affect the maximum value. The minimum value, if not defined on the command line, will be 0. This option can be useful when graphing router traffic when the WAN line uses compression, and thus the throughput may be higher than the WAN line speed".
Logarithmic Auto Scaling Choose if you want logarithmic y-axis scaling.
Rigid Boundaries Mode From the RRDTool manual "Normally rrdgraph will automatically expand the lower and upper limit if the graph contains a value outside the valid range. With this option you can disable this behavior".
Auto Padding If you have ever created RRDTool-based graphs manually, you may have realized how annoying it can be to get text to line up properly. With this option Cacti will do its best to make the columns on your graph legend line up. This option works best when your graph legend has a consistent number of columns.
Allow Graph Export If you choose to use Cacti's static HTML/image export, you can choose whether you want each individual graph to be exported.
Upper Limit The maximum value that will be displayed on the y-axis. This value is ignored is auto-scaling is turned on.
Lower Limit The minimum value that will be displayed on the y-axis. This value is ignored is auto-scaling is turned on.
Base Value Whether you want to base the y-axis labels on 1000 or 1024. This field will typically be set to 1024 for memory and 1000 for traffic measurements.
Unit Value Sets the unit value for the y-axis. You should probably keep the unit short as to keep it readable.
Unit Exponent Value Sets the 10^e scaling of the y-axis. Valid values for this field are between -18 and 18. For example, you could use 3 to display everything in 'k' (kilo) or -6 to display everything in 'u' (micro).
Vertical Label The text to print on the left edge of the graph. Usually is the units the data on the graph is measured in.

Note: For most graph templates, you will want to check the Use Per-Graph Value checkbox for the title field so each graph using this template has its own unique title. It also makes sense to enter an initial value in this field that includes the variable |host_description| for organizational purposes.

When you are finished filling in values for the graph template, click Create and you will be presented with a page similar to the graph edit page.

Figure 11-1. Adding a Graph Template

Graph Items

The first thing you should do is create graph items for this graph template, just like for a regular graph. One difference you will notice is that the Data Sources dropdown will contain a list of data template items rather than data source items. It is important that Cacti can make this association here, so that Cacti doesn't have to make unnecessary assumptions later.

Table 11-2. Field Description: Graph Template Items

Name Description
Data Source If this graph item is to represent some sort of data, you must select a your data source here. Keep in mind that not all graph items have a data source. Graph item types such as COMMENT, VRULE, and HRULE typically do not.
Color Depending on the graph item type, you can select a color for the graph item. This field only applies to the graph item types AREA, STACK, LINE1, LINE2, and LINE3.
Graph Item Type

This field is important because it defines what kind of graph item this is. Types such as AREA, STACK, LINE1, LINE2, and LINE3 are used to represent data on the graph, while COMMENT and GPRINT are used put on the legend. The LEGEND type is specific to Cacti only and can be used if you want to Cacti to automatically create a GPRINT-LAST/GPRINT-AVERAGE/GPRINT-MAXIMUM graph item for you.

Note:: You must always put an AREA item before using STACK or your graph will not render.

Consolidation Function This tells RRDTool which consolidation function to use when representing this data on the graph. You will typically use AVERAGE for most things on the graph area, and LAST/MAXIMUM as well for GPRINT items.
CDEF Function If you want to apply a CDEF function to the graph item, select one here. Check out the CDEF section of the manual for more information.
Value This field is only used with the HRULE/VRULE graph item types. Type any valid integer to draw the line at for HRULE or the time of the day HH:MM for VRULE.
GPRINT Type If this item is a GPRINT, you can choose how you want the number to be formatted. You can add your own in the GPRINT Presets section of Cacti.
Text Format You can enter text to be displayed on the legend here. This field is applicable for all graph item types except for the virtual LEGEND type.
Hard Return Check this box to force graph items onto the next line.

Graph Item Inputs

After creating graph items for your template, you will need to create some graph item inputs. Graph item inputs are unique to graph templates because of the large number of items they sometimes contain. Graph item inputs enable you to take one graph item field, and associate it with multiple graph items.

To create a new graph item input, click Add on the right of the Graph Item Inputs box. There are various fields that must be filled in for every graph item input:

Table 11-3. Field Description: Graph Template Items

Name Description
Name This will be the name used to identify the graph item input on both the graph template and graph edit pages.
Description (Optional) This description will be displayed on the graph edit page of any graph using this template if specified.
Field Type You must choose the field that you are going to associate with one or more graph items.
Associated Graph Items Choose one or more graph items to associate with the field selected for "Field Type". When the user specifies a value for the field, it will be applied to all of the items you select here.

Applying Graph Templates to Graphs

Applying a graph template to a graph is a very simple process. The first thing you must do is select the graph you want to apply the template to under Graph Management. Under the Graph Template Selection box, select the graph template that you want to apply to the graph and click Save. If this is a new graph or the graph and graph template contains an equal number of graph items, the graph template will be automatically applied. If number of graph items varies from the graph to the target graph template, you will be propmted with a warning that your graph will be changed.

Once the template is applied to the graph, you will notice that you can only change values for the fields that you checked Use Per-Graph Value for. You will also notice a new box, called Graph Item Inputs. This is where you can specify values for the graph items inputs that you defined in the graph template. The values specified here will be applied to each graph item tied to the graph item input.

Now any time a change is made to the graph template, it will be automatically propagated to the graphs attached to it.