bashrrdtool

Plotting data from before the graph period in RRDTOOL


I'm using RRDTOL to plot the temperatures for the last 36 hours on a graph. It looks pretty cool: enter image description here

In the rrd itself I'm saving the temperature every minute, and have been doing so for a few weeks. What I'm trying to do is compare the last 36 hours to the preceding 24 hours (compare 2AM last night, to 2AM the previous day, etc.).

I'm using BASH to draw the graphs. Here's the code I use to draw the graph:

# DRAW 36-Hour  graph
/usr/bin/rrdtool graph "$PWD"/outday.png \
--start now-36h --end now \
--alt-autoscale \
-w 425 -h 200 \
--full-size-mode \
--title "Last 36 hours" \
--color CANVAS#36393f00 \
--color BACK#36393f00 \
--color FONT#5b80e0 \
--color GRID#888888 \
--color MGRID#888888 \
--color SHADEA#36393f00 \
--color SHADEB#36393f00 \
--border 0 \
--x-grid HOUR:6:HOUR:80:HOUR:6:0:"%H:%M" \
--left-axis-format %2.0lf \
--watermark "$(date +'%a %b %d %H:%M %Z %Y')" \
DEF:tempo=/usr/local/bin/temp/tempo.rrd:tempo:AVERAGE \
CDEF:up=tempo,0,*,0,EQ,0,1,IF \
TICK:up#3b455e:1.0 \
LINE2:tempo#5b80e0 \
GPRINT:tempo:AVERAGE:"            Average\:%2.1lf" \
GPRINT:tempo:MAX:"Maximum\:%2.0lf            " >/dev/null

I like the way it looks (looks even better on a dark background).

Here's what I tried (doesn't produce any errors when running):

/usr/bin/rrdtool graph "$PWD"/outday2.png \
--start now-36h --end now \
--alt-autoscale \
-w 425 -h 200 \
--full-size-mode \
--title "Last 36 hours" \
--color CANVAS#36393f00 \
--color BACK#36393f00 \
--color FONT#5b80e0 \
--color GRID#888888 \
--color MGRID#888888 \
--color SHADEA#36393f00 \
--color SHADEB#36393f00 \
--border 0 \
--x-grid HOUR:6:HOUR:80:HOUR:6:0:"%H:%M" \
--left-axis-format %2.0lf \
--watermark "$(date +'%a %b %d %H:%M %Z %Y')" \
DEF:tempo=/usr/local/bin/temp/tempo.rrd:tempo:AVERAGE:end=now \
DEF:tempo2=/usr/local/bin/temp/tempo.rrd:tempo:AVERAGE:end=now-24h:start=now-60h \
CDEF:up=tempo,0,*,0,EQ,0,1,IF \
TICK:up#3b455e:1.0 \
LINE2:tempo#5b80e0 \
LINE2:tempo2#5b80e0 \
GPRINT:tempo:AVERAGE:"            Average\:%2.1lf" \
GPRINT:tempo:MAX:"Maximum\:%2.0lf            " >/dev/null

Obviously the lines I'm changing are the DEF:tempo2and LINE2:tempo2 ones. But even when I run this with no errors, The expected second line is just not there.

I suspect that the problem I'm having is that the timeframe is screwing me over somehow, and that I'll need to "edit" the times to shift the second line to the right somehow. But i'm not sure how to do that.


Solution

  • You're almost there, you just need to shift your data timewise otherwise it will display off the lefthand side of graph (which is why you can't see it)

    First of all, make sure that your RRA actually contains the data. You don't show the definition of the RRA, but we'll assume that you have at least 60 hours of data stored in your highest-granularity RRA. If you don't then the graph will get blocky or disappear.

    Next, you correctly have the definition of your second dataset tempo2 selecting the data from yesterday, but need to time-shift it by one day to make it overlay with the graphing time window:

    DEF:tempo=/usr/local/bin/temp/tempo.rrd:tempo:AVERAGE:end=now \
    DEF:tempo2=/usr/local/bin/temp/tempo.rrd:tempo:AVERAGE:end=now-24h:start=now-60h \
    SHIFT:tempo2:86400 \
    

    The SHIFT directive tells RRDTool to shift the time of that dataset by 24 hours, so it will overlay the graph time window. With this, you should be able to see it. I suggest using a different colour though so as not to cause confusion.

    LINE2:tempo#5b80e0:Temperature \
    LINE2:tempo2#abf0ff:Yesterday \
    

    You might also want to take a look at the TREND and PREDICT functions that RRDTool provides. These can give you an even better indicator of what is 'normal' for your dataset.