When graphing with RRDTool, I have added two VRULEs. I'm graphing temperature, and I would like to have the area between them shaded in on the graph. Does RRDTool have any option like this? I've perused https://oss.oetiker.ch/rrdtool/doc/rrdgraph_graph.en.html and can't find anything.
1 Answers
Yes, this is possible, though you need to do a little trick to achieve it. The Routers2 software uses this trick to highlight Working Hours during the time window.
In order to do this, you create a dummy CDEF
that returns a time series that is +INF
during the highlighted window, and 0 elsewhere. Then, you graph this as an AREA
, either before your lines, or after (with transparentcy).
The trick is that the CDEF
has to be based on a DEF
, though it can throw away the data and then calculate based on the TIME
value instead.
For example (simplified for clarity);
rrdtool graph output.png \
DEF:x=file.rrd:ds:AVERAGE \
CDEF:bg=x,POP,0,INF,TIME,$mintime,$maxtime,LIMIT,UN,IF \
AREA:bg#ff808080 \
LINE:x#00ff00:Value \
VRULE:$mintime#ff8080 \
VRULE:$maxtime#ff8080
This will draw a line (in green) for the data; behind it is a seethrough pink highlight between times $mintime
and $maxtime
, and at these two times, a red VRULE
is overlaid.
Note how the CDEF
throws away the initial value of x, and instead uses LIMIT
to tell if the sample time is in the range, subsequently using IF
to give a value of either 0 or INF
depending on the result. This is then used for the AREA
that forms the highlight.
Instead of using a set $mintime
and $maxtime
, you could instead use the value of LTIME
(which takes into account your local timezone offset) to calculate the actual time of day, and highlight between 9am and 5pm M-F. This is the trick used by Routers2 to enable it to highlight multiple areas for working hours.

- 3,754
- 3
- 22
- 39
-
Thanks for your reply Steve! I'll check out the rrdtool man page tomorrow so I can understand more of what's going on. Glad to see it's possible. BTW, great name -- mine is Stephen. – pkSML Feb 06 '21 at 05:35
-
1For the really uninitiated, $mintime and $maxtime are seconds since epoch. – davidgo Aug 09 '22 at 08:54