[mrtg] RPN question with high and low bounds
Alex van den Bogaerdt
alex at vandenbogaerdt.nl
Thu Mar 3 20:07:28 CET 2011
----- Original Message -----
From: "Mark Ter Morshuizen" <mark at itbox.co.za>
To: <mrtg at lists.oetiker.ch>
Sent: Thursday, March 03, 2011 6:58 PM
Subject: [mrtg] RPN question with high and low bounds
[ RRDtool question; next time please use the RRDtool mailing list, thanks ]
> Hi,
>
> I'm trying to do a graph that's red for too hot, green for OK, and blue
> for
> too cold. The script below sort of works but only if I overlay the red and
> blue over the green. I guess that's because of the CDEF:righttemp line
> doing
> the wrong thing. I only want it to show if the temperature is between $hi
> and
> $lo. It shows all the time. Why?
[snip]
> hi=30
> lo=27
[snip]
> CDEF:toohot=mytemp,$hi,GE,mytemp,UNKN,IF \
if (mytemp >= $hi) return mytemp, else return UNKN
> CDEF:righttemp=mytemp,$lo,GT,$hi,LT,mytemp,UNKN,IF \
if (mytemp > $lo) returns a boolean, 1 or 0
if that boolean < $hi then return mytemp, else return UNKN
As both 0 and 1 are smaller than $hi, you will always get mytemp back.
New CDEF below.
> CDEF:toocold=mytemp,$lo,LE,mytemp,UNKN,IF \
if (mytemp <= $lo) return mytemp, else return UNKN
> LINE:righttemp#00AA00:"Temperature OK" \
> LINE:toohot#AA0000:"Too Hot" \
> LINE:toocold#0000AA:"Too Cold"
If, after correcting the CDEF, results are still not nice, try using AREA.
There may be discontinuities when using LINE.
mini tutorial for the RPN:
You want UNKN if mytemp<$lo (or <=, easy to change). You also want UNKN if
mytemp > (or >=) $hi. Else you want mytemp.
First see if LIMIT is usable. It includes the boundaries, so if these are
off limits, you need to slightly alter $hi and/or $lo.
Chances are you can use LIMIT, unless you are really not able to use e.g.
27.0001 .. 29.9999. Or maybe it is not a problem to make 27 and 30 green.
For educational purposes, here's some solutions using GT and LT.
(please forgive me for not testing these. If there are mistakes, so be it.
Correct them please)
> CDEF:righttemp=mytemp,$lo,GT,$hi,LT,mytemp,UNKN,IF \
First create two booleans:
[part1] mytemp,$lo,GT
[part2] mytemp,$hi,LT
multiply to get a logical AND:
[part3] *
use it in your IF statement:
[part4] mytemp,UNKN,IF
complete statement:
CDEF:righttemp=mytemp,$lo,GT,mytemp,$hi,LT,*,mytemp,UNKN,IF
Same result, reverse logic:
CDEF:righttemp=mytemp,$lo,$LE,mytemp,$hi,GE,+,UNKN,mytemp,IF
Another solution:
if (x>$lo) then if (x<$hi) then mytemp else UNKN
[part1] mytemp,$lo,GT
[part2] {to be determined},UNKN,IF
[part3] mytemp,$hi,LT
[part4] mytemp,UNKN,IF
Part 4 is the 2nd IF. It uses the boolean value coming from part 3.
The result of part3+part4 is to be used in part 2.
complete statement:
CDEF:righttemp=mytemp,$lo,GT,mytemp,$hi,LT,mytemp,UNKN,IF,UNKN,IF
More information about the mrtg
mailing list