Cacti Templates

I previously wrote about how Cacti uses rrdtool to store and graph data. Cacti uses templates to define how it interacts with rrdtool as well as how it manages devices. Unfortunately, how objects inherit from these templates varies.

  1. Data templates are applied to all data sources associated with them. However, these are only applied when you create a data source (at “rrdtool create” time). Once the RRD file is created, these RRD settings cannot be changed. So if you create a graph (and its underlying data sources), and later realise that you made a mistake in the data template, you can’t fix it with Cacti. If this happens, the easiest solution is to delete the data source and start over. If you really must preserve your data, you’ll find yourself writing complicated scripts to transform the data with rrdtool.
  2. Graph templates are applied to all graphs associated with them. This happens at any time they are drawn (at “rrdtool graph” time). So you can easily edit a graph template and it the changes will be immediately reflected in all graphs using it. It’s easy to duplicate, delete, and modify these. In this area, Cacti really shines.
  3. Host templates define a set of graph templates or data queries applied to a device. Host template settings are only applied when creating a device, or when switching a device from one template to another. These are additive only; removing a graph template from a host template does not remove it from associated devices. And if you edit the host template, your changes are not applied to existing devices.

In addition, Cacti has some settings which should be called templates but aren’t.

  1. RRAs are defined under “Console” -> “Management” -> “Data Sources”. These define “Associated RRA’s” in the data template. Because these are used by data templates, they are also only applied at data source creation time. It is very important to get these right.
  2. GPRINT, CDEF, and Colors all appear under “Console” -> “Management” -> “Graphs”. These define various settings used in graph templates. Each line of a graph template can reference these. These are applied when graphs are drawn, and so like graph templates, can be changed at any time. They are:
    1. GPRINT – defines how values are printed in the legend. Users of C’s sprintf will recognise these.
    2. CDEF – functions to transform or manipulate data before display, in reverse polish notation. CDEFs can be used to convert bits to bytes, change bases, add values, and more.
    3. Colors – defines the colors that can be used to draw graphs. It seems kind of odd that you can’t use arbitrary hex color codes in Cacti. However, by defining them here, you instead get a pull-down selector that shows the color visually.

Tags: ,

Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.