While visualizing performance or activity data using a well-designed chart can be useful, it is frequently desired to be able to compare recent performance against an earlier period of time. Comparisons against historic data help identify changes in trends or other anomalous performance behaviors. In some cases, this can be done simply by extending the time span of the graph. However, expansion of the graphed time span can lead to either an unacceptable loss of resolution or an unacceptably large image. Fortunately, RRDTool can make this type of comparison chart fairly easily without resulting in a loss of fidelity or unwieldy image size.
To begin, it helps to setup a chart that graphs the desired data in a typical manner before adding in the time shifted overlays. The following graph command creates a somewhat typical visualization of the last hour’s network traffic as illustrated by Example 1 graph:
rrdtool graph example.png \ --title "Network Traffic" \ --width=500 \ --slope-mode \ --end=now \ --start=end-1h \ --base=1000 \ DEF:bytesIn=network.rrd:bytesIn:AVERAGE \ DEF:bytesOut=network.rrd:bytesOut:AVERAGE \ CDEF:bpsIn=bytesIn,8,* \ CDEF:bpsOut=bytesOut,8,* \ CDEF:bpsOutNeg=bpsOut,-1,* \ VDEF:bpsInTot=bpsIn,TOTAL \ VDEF:bpsOutTot=bpsOut,TOTAL \ COMMENT:" current min max total\n" \ AREA:bpsIn#FF880044:"Bits/s In " \ GPRINT:bpsIn:LAST:"%6.1lf%s\t" \ GPRINT:bpsIn:MIN:"%6.1lf%s\t" \ GPRINT:bpsIn:MAX:"%6.1lf%s\t" \ GPRINT:bpsInTot:"%6.1lf%s\n" \ LINE1:bpsIn#FF8800CC \ AREA:bpsOutNeg#44C80044:"Bits/s Out" \ GPRINT:bpsOut:LAST:"%6.1lf%s\t" \ GPRINT:bpsOut:MIN:"%6.1lf%s\t" \ GPRINT:bpsOut:MAX:"%6.1lf%s\t" \ GPRINT:bpsOutTot:"%6.1lf%s\n" \ LINE1:bpsOutNeg#44C800CC \ HRULE:0#000000
With the basic chart setup as desired, now the command can be modified to support a time shifted overlay.
First, additional DEF statements need to be defined for time range for the source data to encompass the time span desired for comparison. Note that this is not the same as the graph’s display range; those options (--start and --end) should remain unchanged. The override start time should extend the time frame to the start of the time shifted data. For example, the following would be suitable for comparison of the previous 1 hour:
DEF:bytesInPrevHour=network.rrd:bytesIn:AVERAGE:start=end-2h \ DEF:bytesOutPrevHour=network.rrd:bytesOut:AVERAGE:start=end-2h \
As another example, the following would be suitable for a comparison of the same hour, 1 day (24 hours) ago:
DEF:bytesInPrevDay=network.rrd:bytesIn:AVERAGE:start=end-25h \ DEF:bytesOutPrevDay=network.rrd:bytesOut:AVERAGE:start=end-25h \
Next, a new SHIFT statement needs to be introduced that shifts the data being displayed by the specified number of seconds. The SHIFT statements must be specified after the DEF statements they are shifting. The following statements would shift the newly inserted DEF statements by 1 hour (3600 seconds):
SHIFT:bytesInPrevHour:3600 \ SHIFT:bytesOutPrevHour:3600 \
Next, the CDEF and VDEF operations need to be supplied in order to transform the new data in a consistent manner with the original data.
CDEF:bpsInPrev=bytesInPrevHour,8,* \ CDEF:bpsOutPrev=bytesOutInPrevHour,8,* \ CDEF:bpsOutPrevNeg=bpsOutPrev,-1,* \
Finally, the new elements are ready for graphing. Care should be made to ensure the shifted data is displayed in a distinct manner from the current data so as to prevent visual confusion or obscuring the current data.
LINE1:bpsInPrev#00000088 \ LINE1:bpsOutPrevNeg#00000088 \
Pulling it all together, the following command will pull in the data from the extended time frame, shift it forward by the appropriate amount of time so that it aligns with the displayed time frame, perform the desired transformation options, and finally display the results:
rrdtool graph example.png \ --title "Network Traffic" \ --width=500 \ --slope-mode \ --end=now \ --start=end-1h \ --base=1000 \ DEF:bytesIn=network.rrd:bytesIn:AVERAGE \ DEF:bytesOut=network.rrd:bytesOut:AVERAGE \ DEF:bytesInPrevHour=network.rrd:bytesIn:AVERAGE:start=end-2h \ DEF:bytesOutPrevHour=network.rrd:bytesOut:AVERAGE:start=end-2h \ SHIFT:bytesInPrevHour:3600 \ SHIFT:bytesOutPrevHour:3600 \ CDEF:bpsIn=bytesIn,8,* \ CDEF:bpsOut=bytesOut,8,* \ CDEF:bpsOutNeg=bpsOut,-1,* \ CDEF:bpsInPrev=bytesInPrevHour,8,* \ CDEF:bpsOutPrev=bytesOutInPrevHour,8,* \ CDEF:bpsOutPrevNeg=bpsOutPrev,-1,* \ VDEF:bpsInTot=bpsIn,TOTAL \ VDEF:bpsOutTot=bpsOut,TOTAL \ COMMENT:" current min max total\n" \ AREA:bpsIn#FF880044:"Bits/s In " \ GPRINT:bpsIn:LAST:"%6.1lf%s\t" \ GPRINT:bpsIn:MIN:"%6.1lf%s\t" \ GPRINT:bpsIn:MAX:"%6.1lf%s\t" \ GPRINT:bpsInTot:"%6.1lf%s\n" \ LINE1:bpsIn#FF8800CC \ AREA:bpsOutNeg#44C80044:"Bits/s Out" \ GPRINT:bpsOut:LAST:"%6.1lf%s\t" \ GPRINT:bpsOut:MIN:"%6.1lf%s\t" \ GPRINT:bpsOut:MAX:"%6.1lf%s\t" \ GPRINT:bpsOutTot:"%6.1lf%s\n" \ LINE1:bpsOutNeg#44C800CC \ LINE1:bpsInPrev#00000088 \ LINE1:bpsOutPrevNeg#00000088 \ HRULE:0#000000

