I have the following rrd database:
rrdtool create --start 1699574400 --step 86400 power.rrd \
DS:draw:GAUGE:86400:U:U \
DS:feedin:GAUGE:86400:U:U \
RRA:LAST:0.5:1:395
I fill in "draw" and "feedin" data daily. I want to create a 30 d average graph for a whole year. If I do it like this:
rrdtool graph "average.png" -a "PNG" --alt-autoscale \
--start "end-365d" \
--end "now" \
--width "426" \
--height "250" \
--title "Netzbezug und Einspeisung (30-d-Durchschnitt)" \
"DEF:draw=power.rrd:draw:AVERAGE" \
"DEF:feedin=power.rrd:feedin:AVERAGE" \
"CDEF:draw_t=draw,2592000,TREND" \
"CDEF:feedin_t=feedin,2592000,TREND" \
"AREA:draw_t#696969:Netzbezug (kWh)" \
"AREA:feedin_t#32CD32:Einspeisung (kWh)" \
--grid-dash "1:0" \
--x-grid "MONTH:1:MONTH:1:MONTH:2:00:%m/%Y" \
--y-grid "1:5" \
"HRULE:0#A0A0A0"
The resulting graph covers a whole year, but the first 30 days are missing:
If I change the start to end-395d
, the data I want is included, but I also get that gap at the start:
How can I get rid of that gap, so that I get the time span of the first graph, but with the data of the second one?
The gap is where RRDTool has no data. Since your trend rollup is 30 days, you need 30days of prior data to be able to calculate it, and so it is 'unknown' until after 30 days because it does not have the full 30 days of source data.
First solution
What you need to do is to instead use TRENDNAN
. This is the same as TREND
but still tries to produce a value even if the source data are partially outside the window.
"CDEF:draw_t=draw,2592000,TRENDNAN" \
"CDEF:feedin_t=feedin,2592000,TRENDNAN" \
This will allow a value to be displayed, but not that it will be progressively less accurate as it moves towards the lefthand axis as it is only calculated on the data visible in the graph.
https://oss.oetiker.ch/rrdtool/doc/rrdgraph_rpn.en.html
Second Solution
Alternatively, you can tell RRDTool to retrieve more data than in the display time window from the draw and feedin RRAs. This will allow the TREND
calculation to complete because the data will be available.
--start "end-365d" \
--end "now" \
"DEF:draw=power.rrd:draw:AVERAGE":start=end-396d \
"DEF:feedin=power.rrd:feedin:AVERAGE":start=end-396d \
"CDEF:draw_t=draw,2592000,TREND" \
"CDEF:feedin_t=feedin,2592000,TREND" \
Here, we make the DEF
retrieve 396 days of data, rather than the graph window of 365 days. Note we need 30 days for the trend, plus one for the boundary. This will mean that draw
and feedin
now have data for 30 days to the left of the graph window, and so draw_t
and feedin_t
can be calculated.
https://oss.oetiker.ch/rrdtool/doc/rrdgraph_data.en.html
Summary
The Second solution is better mathematically, but relies on you specifying the size of the extended time window in additional places. So you can pick the one which best suits your application.