[rrd-users] Different Colours in a single plot

Simon Hobson linux at thehobsons.co.uk
Wed Sep 8 21:48:49 CEST 2010


Thomas Lansdale wrote:

>I wish to plot one data source on a graph but colour the plot 
>differently depending on the value. I have three threshold values to 
>indicate availability (available, affected, degraded) and they 
>should be plotted green, orange, red respectively.
>
>I have managed to find a graph that shows something just like this 
>(generated with rrdtool) but it is unclear how to re-produce this 
>using the tool. Can anyone offer any insight into this, perhaps an 
>example command to generate a graph?
>
>The link where I saw the plot is: 
>http://oss.oetiker.ch/rrdtool/gallery/ (The graph is: DOCSIS 
>UPSTREAM UTILIZATION)

Coincidentally, I added just such a feature to one of my graphs last 
week ! The extract of BASH script is :
         DEF:op_pc_ave=${RRDPath}/${RRDName}:op_pc:AVERAGE
         DEF:op_pc_min=${RRDPath}/${RRDName}:op_pc:MIN
         DEF:op_pc_max=${RRDPath}/${RRDName}:op_pc:MAX
         CDEF:op_pc_spread=op_pc_max,op_pc_min,-
         VDEF:v_op_pc_ave=op_pc_ave,AVERAGE
         VDEF:v_op_pc_max=op_pc_max,MAXIMUM
         VDEF:v_op_pc_min=op_pc_min,MINIMUM

         CDEF:alarm1=op_pc_max,${Plimit},100,LIMIT
         AREA:alarm1#FFBFBF:
         CDEF:alarm2=op_pc_max,99,10000,LIMIT
         AREA:alarm2#FF0000:

         COMMENT:\"                  min      ave      max\n\"
         HRULE:${Plimit}#7F0000
         AREA:op_pc_min#FFFFFF00:
         AREA:op_pc_spread#BFBFFF::STACK
         LINE1:op_pc_ave#0000FF:\"%age Power\"
         GPRINT:v_op_pc_min:\"%6.0lf \"
         GPRINT:v_op_pc_ave:\"%6.0lf \"
         GPRINT:v_op_pc_max:\"%6.0lf\"

basically, what I've done is created the data series alarm1 using the 
LIMIT function which returns the value if it's between the value 
${Plimit} (a shell variable defined elsewhere which shows the power 
limit for our UPS while retaining n+1 redundancy) and 100, and 
unknown if the value is outside this range. It then draws this as an 
area with a pale red (pink) colour.

Similarly, alarm 2 is the power if over 99% or unknown otherwise, and 
this series is drawn as a solid red area.

The actual power is then drawn as a line overlaid on an area showing 
the spread (min to max).

The result is that if we lose our redundancy the area under the line 
turns pink, if we reach 99% it turns red.

I'm sure there are other ways of doing it. One other obvious way is :
CDEF:alarm1=op_pc_max,${Plimit},GT,op_pc_max,UNKN
which does much the same thing - sets alarm1 to the value if it's 
greater than the limit, or unknown if it isn't.

-- 
Simon Hobson

Visit http://www.magpiesnestpublishing.co.uk/ for books by acclaimed
author Gladys Hobson. Novels - poetry - short stories - ideal as
Christmas stocking fillers. Some available as e-books.



More information about the rrd-users mailing list