[rrd-users] calculate change / graph change between last and last-1

Alex van den Bogaerdt alex at vandenbogaerdt.nl
Wed Dec 23 02:21:26 CET 2009


----- Original Message ----- 
From: "John Stile" <john at stilen.com>
To: "rrd-users" <rrd-users at lists.oetiker.ch>
Sent: Tuesday, December 22, 2009 8:03 PM
Subject: Re: [rrd-users] calculate change / graph change between last and 
last-1


> Is it a mistake to want to plot the difference between stored data
> values?

Well...

first of all: data values aren't stored. You can emulate this, but you're 
'abusing' the tool to do something it wasn't really designed for.  That 
doesn't matter, as long as you keep it in mind and consider this for further 
'abuse'.  As long as you understand normalization and consolidation, you'll 
be fine when you pretend that GAUGE 'stores values'.

This said, you can probably do what you want. For instance, if your interval 
is 5 minutes, you can do:

time2 = now - (now%300) # whatever it takes you to get the most recent 
updated interval
time1 = time2 - 300 # 5 minutes before
val1=`rrdtool graph nothing --start end-300s --end time1 DEF:x... 
PRINT:x:AVERAGE:...`
val2=`rrdtool graph nothing --start end-300s --end time2 DEF:x... 
PRINT:x:AVERAGE:...`
diff=val2-val1

You can probably avoid the second extra rrdtool graph invocation and do this 
directly from your existing script. However: It's probably best to compute 
the difference outside rrdtool, why waste all those resources? You'd need a 
CDEF inside rrdtool and probably use more resources than a simple command 
like above.

There is, afaik, no 'last-1' command.

Don't know if it's going to work, but DEF takes time parameters.  Maybe you 
can experiment with something like:

time2 = now - (now % 300)
time1 = time1 - 300
rrdtool ... DEF:x2=....:start end-300s:endtime2
rrdtool ... DEF:x1=....:start end-300s:endtime1
rrdtool ... DEF:x3=....
{graph x3}
{compute x2-x1}
GPRINT:{outcome of x2-x1}

Last time I checked this it didn't work, because x1 and x2 shared the same 
data. Dunno if that's changed.

Another approach maybe using SHIFT. Shift the time to look at by your 
interval, compute and plot the difference.

HTH
Alex




More information about the rrd-users mailing list