[rrd-users] Graph colors and time
Alex van den Bogaerdt
alex at vandenbogaerdt.nl
Sun Nov 4 10:03:06 CET 2012
> I am trying to generate a graph to display power usage in my house. I
> would like to display part of the graph with different colors for
> off-peak times (22:30-6:30) and peak hours (6:30-22:30). All data are
> stored in the same DS. I look at the documentation but I don't figure
> out how to do it. Sorry if I missed it.
> Thank you to whom may help to direct me to the solution.
Best is to use a different background color, and keep the actual line
showing your usage in the same color, this to avoid discontinuities.
Using LTIME you figure out local time. Using CDEF you make choices/branches
in your graphing code. The trick is to return INF when you want to display
that particular part of the background, and UNKN if not. Then graph the
result in an AREA.
One CDEF returns INF between 6.30am and 10.30am, the other during the other
Although you are not using your actual data when doing this, you still need
to build an array with time and data, or else CDEF will complain. So you
start with your data and then simply discard it (in that CDEF only, of
>From memory, to get you started:
(and I believe some existing examples can be found in either the
documentation and/or in the various tutorials)
This starts with fetching data and immediately discarding it, thus building
our array to work with.
Then you push unknown and infinite; which one gets used is determined by the
The numbers are (or: should be, you do checking and correcting) 6.30 and
6.30 is not included because the interval _ending_ at that time is outside
your specified range.
LTIME,86400,% should provide wall clock time in seconds since midnight.
LIMIT looks if that time is between 6.30 (non inclusive) and 22.30
UN sees if LIMIT returned an unknown
IF uses the result of UN to return either UNKN or INF.
For the other CDEF it is simply a matter of reversing the previous result:
IF peak is UNknown then return INF else UNKNown.
Oh by the way: you never can graph what is not there. If you display a lot
of time in one graph, then chances are you do not have boundaries at 6.30
and 22.30. If for instance each pixel column is worth an hour, you will be
coloring 6am to 10pm: the interval ending at 6am is not included because it
ends before 23401. the interval ending at 11pm is not included because it
ends after 81000.
More information about the rrd-users