Valid HTML 4.01 Strict!
Valid CSS!

Shifting data on the X-axis and/or the Y-axis

Index

Intro
Rates and time
Moving data up or down
Moving data left or right
Example
Wrapup

Intro

RRDtool stores rates during time intervals. Sometimes you do not want to present the data "as is", you want to move it up (or down) a bit. Or maybe you like to move it to the right. This tutorial is going to show you how it works.

Rates and time

While not stored in an RRA, numbers in there have some implicit properties. Each of the rows in one single RRA represent the same amount of time, an interval. The number stored in such a row represents a rate. Last but not least: the position of the row in this RRA defines its end time. Yes, that's correct, end time. Together with its duration you also know its start time.

In short, each number represents an area starting at some place on the X-axis (the end-time of this row), stretching out up (its rate) and left (its duration).

Moving data up or down

Normally a rate is shown relative to the X-axis. The higher the rate, the higher the line or area. In some cases it is better to do it different.

Modifying your data

I've made plenty of graphs that multiplied ifInOctets (bytes going in) by -1. This way it ends up below the X-axis, as a mirror image of its original. This and similar stuff can be done using a simple CDEF:

This modifies the original data (only when graphing!) and successive computations on "modified" reflect this modification.

If you need to compute averages and such, do it using original, even if you display modified.

Using a similar CDEF, you can multiply your data to display bits in stead of bytes. In such a case, you may want to use modified to compute averages.

Stacking your data

I also created graphs that showed one value on top of another. For instance, when showing bot HTTP and FTP traffic in the same graph, you could display FTP starting from the X-axis, then in a different color show HTTP traffic on top of the FTP traffic. This can be done using STACK:

RRDtool 1.2 and later can do it somewhat different. It has the advantage that you can also stack an AREA on top of a LINE:

Doing this does not modify your data. Any computations done on ds1 are not influenced by stacking it.

Offset your data

If you want to compare two different datasets, you could plot two different graphs. You could also choose to show both datasets into one graph, one above the other. For this you need to alter the bottom part of one dataset so that it isn't on the X-axis.

The CDEF is a hack. It uses ds1 because CDEFs must have a datasource, but it immediately destroys the data from ds1 again. What remains is the fixed value 100000. This fixed value is then displayed as an invisible area, and ds1 is stacked on top of it.

RRDtool 1.2 and later can do it much more convenient:

An invisible line is drawn at 100000, on top of it an area is stacked. A much cleaner way of doing things if you ask me.

Moving data left or right

Moving data on the X-axis can only be done by rrdtool 1.2 and later. It works by fetching data from an RRD using different start and end parameters, offsetting its time component, and displaying it. Here's how:

I'm careful here to select specific times, not using "now", time boundaries are on well defined moments, and so on. Also notice how I use a number of seconds to move the past forward in time. There will be two lines: a blue one, showing yesterday entirely, and a red one, showing the day before yesterday. They will probably overlap a lot, that's why I didn't use AREAs.

I cannot use "day" or similar as a parameter to SHIFT. A day is not always 86400 seconds, a week is not always 604800 seconds, and so on. The only valid words could have been minute and hour but for simplicity this isn't allowed either, only a number can be used. Positive numbers move the data to the right (forward in time).

Example

The following example moves data right and up. You get to see three images, respectively yesterday, the day before, and those two days combined. The data itself is meaningless, the RRD was created just for this example.

rrdtool graph day_a.png \
        --end midnight \
        --start end-86400 \
        --upper-limit 400000 \
	--lower-limit -100000 \
        DEF:a=test.rrd:ds0:AVERAGE \
        LINE:a\#00CC00:a

rrdtool graph day_b.png \
        --end midnight-86400 \
        --start end-86400 \
        --upper-limit 400000 \
	--lower-limit -100000 \
        DEF:b=test.rrd:ds0:AVERAGE \
        LINE:b\#FF0000:b

rrdtool graph day_c.png \
        --end midnight \
        --start end-86400 \
        --upper-limit 400000 \
	--lower-limit -100000 \
        DEF:a=test.rrd:ds0:AVERAGE \
        DEF:b=test.rrd:ds0:AVERAGE:start=end-86400:end=midnight-86400 \
        LINE:a\#00CC00:a \
        LINE:200000 \
        SHIFT:b:86400 \
        LINE:b\#FF0000:b:STACK


Upper and lower limit are set so that there's plenty of room around the lines and all three graphs have the same amount of Y-axis. Offsetting the red line by 200,000 was enough for me, you may want to change that value (and possibly the upper-limit as well) if you try this example.

Wrapup

This completes the tutorial on shifting data. I hope you find it useful.

Do you like this information? Tell others! Don't you? Tell me!

This page was created by Alex van den Bogaerdt, an independent IT consultant. If you want to provide feedback or if you want to hire me please see contact alex.
Back to the top of this page. You can also go to the index