I upgraded some rrdtool graphs today (in the examples below, I was using weekly graphs). First I smoothed out some of the data with TREND. That was pretty easy, you just specify which data and the timeframe it should use to smooth out: CDEF:trend_data=data,21600,TREND smooths out data by 6 hours (21600 seconds). trend_data can be used afterwards (for LINE, AREA, ….) The DEF will have to be expanded a bit so that enough data is available for the TREND, I just added a days woth of data to begining and end by adding the following to the end of my DEF statement :start=now-8d:end=now+1d
The whole trend would look kinda like this:
rrdtool graph image.png \
–width 500 –height 200 \
–end now –start now-7d \
–vertical-label “data” \
DEF:data=some.rrd:data:AVERAGE:start=now-8d:end=now+1d \
CDEF:trend_data=data,21600,TREND \
LINE1:trend_data#000000:”smoothed out data”
The next thing I played around with, was extrapolating the data and drawing a projection. Fist thing to do, is open up the graph to end a few days in the future, easy to do with the –start and –end options: –end now+3d –start now-7d Now lets make DEF over the time range we want to use for the projection, this example will use the data of the last two weeks: DEF:data=some.rrd:data:AVERAGE:start=now-2w:end=now+3d All we need now is a little rrd magic I found in the depths of the internet:
VDEF:D=data,LSLSLOPE \
VDEF:H=data,LSLINT \
CDEF:projection=data,POP,D,COUNT,*,H,+ \
LINE1:projection#BB2030:”2 week projection”
Ok, if we throw both trend and projection together we end up with a cute little rrd mess that looks something like this:
rrdtool graph image.png \
–width 500 –height 200 \
–end now –start now-7d \
–vertical-label “data” \
DEF:data1=some.rrd:data:AVERAGE:start=now-8d:end=now+1d \
DEF:data2=some.rrd:data:AVERAGE:start=now-2w:end=now+3d \
CDEF:trend_data=data1,21600,TREND \
LINE1:trend_data#000000:”smoothed out data” \
VDEF:D=data2,LSLSLOPE \
VDEF:H=data2,LSLINT \
CDEF:projection=data2,POP,D,COUNT,*,H,+ \
LINE1:projection#BB2030:”2 week projection”