[rrd-users] [Fwd: Re: Getting Started with RRD]
Alex van den Bogaerdt
alex at ergens.op.het.net
Wed Oct 31 13:20:14 CET 2007
On Wed, Oct 31, 2007 at 01:16:03AM -0400, Lex wrote:
> Now comes to the time to 'beautify' the graphs themselves, and I would like
> to add a gradient to the area below the graph line.
>
> In one case, the graph is a percentage, where:
>
> - 0 to 60% should be gree
> - 61 to 90% yellow
> - 90 to 100% red
>
> ...with a gradient in between... for example, the Temperature graph on the
> examples page at that links to
> http://pampa.tche.br/temperatura/temperatura.cgi would do just perfectly.
> Unfortunately...I can't find any examples of how this is done.
Look in the documentation and find tutorials for rrdtool, cdef, rpn.
Then convert the following basic idea to CDEF and AREA statements:
show everything in red
if (value is above 90%) then show 90%, else everything in yellow
if (value is above 60%) then show 60%, else everything in grey
This means you plot everying in red, overlay part of the value with
yellow, and part of it with grey. You end up with grey, perhaps with
a bit of yellow above it, and perhaps with a bit of red above that.
In CDEF, an if-then-else looks like: a,b,c,IF
where (a) is (boolean, such as: value is above 90%)
where (b) is (if true, e.g. 90% of value)
where (c) is (if false, e.g. value)
Thus:
if (value>9000000) then 9000000 else value
becomes: value,9000000,GT,9000000,value
Double if:
if (val>1) then
if (val<10) then
val
else
10
else
1
Split into two if-then-else statements, convert and combine:
a,b,c,IF this is: if (a) then (b) else (c)
x,y,z,IF
a,x,y,z,IF,c,IF this is: if (a) then {if(x) then (y) else (z)} else (c)
a: val>1
b: result of other if
c: 1
x: val<10
y: val
z: 10
convert a and x:
a: val,1,GT
x: val,10,LT
convert abc: val,1,GT,b,1,IF (todo: b)
convert xyz: val,10,LT,val,10,IF
substitute b: val,1,GT,val,10,LT,val,10,IF,1,IF
How do you find out what 90% is? This depends on what you want.
Sometimes, 90% will be 9,000,000 (for 10Mbps ethernet). Sometimes
it will be 4,500,000 (for 10Mbps ethernet, still usable).
Or maybe you have {blue,green,red} for {too cold,comfortable,too warm}.
Sometimes it should be what is visible on the graph itself. You will
need to use rrdtool v1.2 (or above) which knows VDEF:
VDEF:max=temperature,MAXIMUM
and then use "max" instead of a number in your CDEFs.
You may even want to setup your databases not only with averages but
also with minimum and maximum rates, and then plot only the part between
these two rates:
difference=maximum-minimum
plot minimum using transparency
stack the difference using a colour
and if you want different colours:
difference=maximum-minimum
if (maximum>90%) then y1=difference, y2=blank, y3=blank
else if (maximum>60%) then y1=blank, y2=difference, y3=blank
else y1=blank,y2=blank,y3=difference
use "UNKN" (unknown) for blank, this will not show up on the graph.
plot minimum using transparency, stack y1 using red
plot minimum using transparency, stack y2 using yellow
plot minimum using transparency, stack y3 using grey
Transparency is achieved by not setting a colour, or by setting its
opacity to zero (v1.2 and above only):
AREA:value
or
AREA:value#FFFFFF00
(any colour RRGGBBAA will do, as long as AA is zero)
The resulting set of CDEFs and AREAs will look complex but really is
nothing more than straight forward programming.
Some code for v1.2 (untested, you debug and/or modify):
DEF:min=temp.rrd:temperature:MIN
DEF:max=temp.rrd:temperature:MAX
CDEF:dif=max,min,-
CDEF:y1=max,9000000,GT,dif,UNKN,IF
CDEF:y2=max,6000000,GT,max,9000000,LE,dif,UNKN,IF,UNKN,IF
CDEF:y3=max,6000000,LE,dif,UNKN,IF
AREA:min
AREA:y1#F00:busy:STACK
AREA:min
AREA:y2#0C0:normal:STACK
AREA:min
AREA:y3#00F:idle:STACK
If you want 90% of the current maximum, replace 9000000 with the
appropriate VDEF
example:
VDEF:maxseen=max,MAXIMUM
then replace "9000000" with "maxseen,0.9,*" and so on
HTH
--
Alex van den Bogaerdt
http://www.vandenbogaerdt.nl/rrdtool/
More information about the rrd-users
mailing list