Basic Area Graphs with RRDTool

Introduction

This post describes some basic techniques for generating area charts using RRD tool.  It builds upon the previous Line Graphs posting which describes DEFs and other basic graphing options.  The data used for the examples was generated using the tool specified in the RRD Example Data posting.

Area Chart Graphing Directives

As specified in the Line Graphs posting, the data definitions (DEFs) must be declared prior to the display directives.  The general format for an area directive is as follows:

AREA:Label#Color:Legend:STACK

Label refers to the label given to a previously defined data definition (DEF).  This defines the source of the data to be graphed.

Color defines the color of the line or area graph.  This is expressed in the web-standard  RGB hexadecimal triplet and must be separated from the label by a ‘#’.  Example color definitions are: 333399 (blue), 33FF00 (bright green), and CC0000 (red).  If the color is not specified, then the area will be “invisible”.

Legend is the text associated with the legend entry for the graph.  It is an optional element, and if it is omitted the ‘:’ separator should also be omitted.

STACK specifies that the results in the graph element be offset from the top of the previous display output instead of the normal 0-based offset.  It is case-sensitive and should always be specified in all-caps.  It is an optional element, and if it is omitted the ‘:’ separator should also be omitted.  To specify a stacked element without a legend, simply omit any entry for the legend but remember the colon.  (e.g. AREA:label#00FFAA::STACK)

Examples

Example 1

This is a simple example of an area graph.  In this case, there is only one data element defined and displayed (“disk1″).

rrdtool graph "Example 1.png" \
--start "end-28 hours" --end "Dec 31, 2009" \
--imgformat PNG --width 500 --height 120 \
--title "Example 1" \
--vertical-label "Bytes" \
DEF:disk1=sysinfo.rrd:disk_used:AVERAGE \
AREA:disk1#0000FF:"Disk 1"

Example 1

Example 2

This example illustrates more than one display element.  In this case, the elements are not stacked and so both use the default 0-based offset.  Note that the order of display directives also defines the drawing order, which may result in some (or all) of an area graph in being hidden.

rrdtool graph "Example 2.png" \
--start "end-48 hours" --end "Jan 4, 2009" \
--imgformat PNG --width 500 --height 120 \
--title "Example 2" \
--vertical-label "Bytes" \
DEF:disk1=sysinfo.rrd:disk_used:AVERAGE \
DEF:disk2=sysinfo.rrd:disk2_used:AVERAGE \
AREA:disk1#0000FF:"Disk 1" \
AREA:disk2#FF0000:"Disk 2"

Example 2

Example 3

This example illustrates the use of the STACK option for the AREA directive.  Remember that the STACK offsets the data display to start from the top of the previously displayed element.  If there is no previous element, then the STACK option uses the default 0-based offset.  Any number of display directives can use the STACK option.  A frequent use of the STACK option is to illustrate a “summation” of a set of servers or services.

Compare this graph with that of Example 2, which covers the same set of data.

rrdtool graph "Example 3.png" \
--start "end-48 hours" --end "Jan 4, 2009" \
--imgformat PNG --width 500 --height 120 \
--title "Example 3" \
--vertical-label "Bytes" \
DEF:disk1=sysinfo.rrd:disk_used:AVERAGE \
DEF:disk2=sysinfo.rrd:disk2_used:AVERAGE \
AREA:disk1#0000FF:"Disk 1":STACK \
AREA:disk2#FF0000:"Disk 2":STACK

Example 3

Example 4

This example illustrates the technique of making an “invisible” element.  In this case, the “disk1″ directive has no color or legend specified.  However, despite it not being displayed, it is still present as applicable to the STACK option for the “disk2″ element.

rrdtool graph "Example 4.png" \
--start "end-48 hours" --end "Jan 4, 2009" \
--imgformat PNG --width 500 --height 120 \
--title "Example 4" \
--vertical-label "Bytes" \
DEF:disk1=sysinfo.rrd:disk_used:AVERAGE \
DEF:disk2=sysinfo.rrd:disk2_used:AVERAGE \
AREA:disk1::STACK \
AREA:disk2#FF0000:"Disk 2":STACK

Example 4

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>