Combining Multiple Graphs in Cricket
The existing documentation for visualizing multiple graphs simultaneously in Cricket is fairly limited. This document is intended to provide a more detailed tutorial.
Can and Can't
Before proceeding any further, let's first deal with what things can and cannot be done and assess the relative difficulty of each.
- Multiple graphs on one page from identical target types
- If you simply wish to display a single page including multiple graphs of identical target-type, it is straightforward to do.
- Multiple datapoints from identical target types in a single graph
- If you wish multiple targets of identical target-type to be merged into a single graph, this is also easy.
- Simple math operations on identical sources in different targets of same target type
- If, for example, you wish to average, sum or otherwise arithmetically manipulate identical individual sources within different targets of the same target-type, this is easy.
Pretty much anything else gets complicated. At the end I address a few techniques I have used successfully to do some of those things, but none is particularly easy. In some cases, the Cricket developers might actively discourage the techniques I employ because ongoing support might disappear.
Terminology and the Basics
Before proceeding, it is critical that you understand basic terminology used in Cricket.
- Target
- In Cricket, a Target refers to a single node in a configuration tree. A Target presents an arbitrary number of discrete Datasources grouped into Views of one or more Datasources. When navigating through the grapher's GUI, the Target represents the table row in which links to the individual graphs may be found.
- Datasource
- A Datasource represents a single series of data, typically representing a single SNMP OID as it is collected and stored over time. Each Datasource represents a single set of data points in a graph (what in Excel would be called a Series). Datasources are not directly exposed to the grapher GUI.
- View
- A View constitutes a single set of graphs (collected over various time periods) presented within a target. For example, in a graph of an interface, different Views might present the inbound and outbound throughput, the error rate, the inbound and outbound packet rates and so on. Note that a single view can combine multiple Datasources, as in the case of throughput (inbound and outbound).
- TargetType
- The target-type/TargetType controls how a Target interprets the data it collects, defining the Datasources and Views for the Target. In the Cricket configuration files, you define the TargetType by name and then refer to a particular Target as utilizing a "target-type".
- RRD file
- For every Target, a single RRD file is created. Internally in the database, a single "column" of data exists for every Datasource defined to exist in the Target.
Example
To begin, let us examine a relatively simple example. I have setup this server to monitor itself with Cricket, and the grapher can be accessed here. I collect some data from Net-SNMP and generate graphs here. We will be looking at the interface graphs, and the relevant bits of configuration used to generate graphs for the interfaces de0 and xl0 are here:
target de0
target-type = interface
interface-name= "de0"
inst = map(interface-name)
short-desc = "Interface statistics for de0"
order = 5
target xl0
target-type = interface
interface-name= "xl0"
inst = map(interface-name)
short-desc = "xl0"
order = 5
targets directive
In Cricket, the Targets directive can be used to create a virtual Target for which no corresponding RRD file exists. To present graphs for each View, Cricket refers to a list of individual Targets and retrieves the corresponding graph for the relevant View. The resulting page presenting the graphs links to each Target's graphs instead.
For example, on my simple example site I created a target called "targets-sample". Click through the graphs for "targets-sample" and compare them to the "xl0" and "de0" graphs. This is configuration that I used:
target targets-sample
target-type = interface
targets = "xl0; de0"
short-desc = "Sample of using targets directive"
order = 4
mtargets directive
Similarly to Targets, Mtargets collects multiple targets together for convenient viewing in graphs. However, rather than presenting several graphs on a page, Mtargets causes the grapher to merge the datasources all onto a single graph. As noted by the documentation, this option works best if you are not explicitly setting the color and draw-as attributes of the datasources you are graphing, since Cricket will otherwise produce graphs that will likely be difficult to read.
To view an example, click on the "mtargets-sample" target on my example site. The configuration I used looks like the following:
target mtargets-sample
target-type = interface
mtargets = "xl0; de0"
short-desc = "Sample of using mtargets directive"
order = 4
mtargets-ops directive
Finally, mtargets-ops can be used to perform simple arithematic on your Mtargets, yielding a graph with as many Datasources as in the underlying singular Target graphs. Cricket understands the builtin operations "sum()" and "avg()" as well as comma-separated lists of operations. For example, when dealing with six Mtargets, sum() is equivalent to "+,+,+,+,+".
My example site performs a simple sum() in the "mtargets-ops-sample". Please take a look, and see the configuration:
target mtargets-ops-sample
target-type = interface
mtargets = "xl0; de0"
mtargets-ops = sum()
short-desc = "Sample of using mtargets-ops sum() directive"
order = 4
Digging Deeper
So far I have demonstrated how to do things with Cricket that are very well-planned for and well understood. But sometimes you might like to do things that are more complicated and for which no ready means of expression exists in Cricket. Here are some bits of advice on doing less obvious things involving multiple datasources.
Mixing Datasources
One of the first things you might notice is that the existing support for multiple datasource presentation is that it only works for correspondingly-aligned datasources within respective Targets. You cannot easily, for example, add ifInOctets and ifOutOctets to display gross bidirectional traffic across an interface. I have written a small tool for getting around this limitation. Other tools may exist.
Nesting multi-Targets
I had never thought of a practical reason to do it, but the question seems valid. Is it possible to use a Target itself generated with mtargets-ops within another nested multi-Target? I don't know the answer to this question, but would be interested to know the answer.
Trimming Datasources
There may be times when you wish to create a multi-Target from a limited subset of the Datasources and Views in a set of Targets. In my small example site the "all_disks" target collects the percentages from all disks being monitored, however I felt that the raw utilization statistics would be useless to combine because of the differing scales (disks will be of varying sizes). So I finessed things by creating a dummy TargetType identical to the TargetType of the disks, but defining only the first datasource.
target all_disks
target-type = diskPercent
mtargets = "root; home; usr; var; usr_obj; usr_ports; usr_local"
short-desc = "Combined Utilization"
order = 3
Compare the TargetTypes:
targetType disk
ds = "dskPercent, dskTotal, dskAvail"
view = "Percent Used: dskPercent, Bytes: dskTotal dskAvail"
targetType diskPercent
ds = "dskPercent"
view = "Percent Used: dskPercent"
Note that this technique is simplest (or maybe at all possible) when the "interesting" datasources occur first in the regular TargetType.
(C) 2002, Michael Han
$Id: multiple.html,v 1.4 2003/06/28 22:01:43 mikehan Exp $