=head1 DESCRIPTION
-If you provide a question, I will try to provide an answer in the next
-release of this tutorial. No feedback equals no changes! Additions to
+Intention of this document: to provide some examples of the commonly
+used parts of RRDtool's CDEF language.
+
+If you think some important feature is not explained properly, and if
+adding it to this document would benefit most users, please do ask me
+to add it. I will then try to provide an answer in the next release
+of this tutorial. No feedback equals no changes! Additions to
this document are also welcome. -- Alex van den Bogaerdt
E<lt>alex@ergens.op.het.netE<gt>
||
-=back
+=back
Processing the stack (step 5) will retrieve one value from the stack
(from the right at step 4). This is the operation multiply and this
This is not very intuitive (at least most people don't think so). For
the function f(A,B) you reverse the position of "f", but you do not
-reverse the order of the variables.
+reverse the order of the variables.
=head1 Converting your wishes to RPN
router1.rrd:link2in
router2.rrd:link1in
router3.rrd:link1in
- router3.rrd:link2in
+ router3.rrd:link2in
-------------------- +
(outcome of the sum)
not matter if you add a to b and then add c to the result or first
add b to c and then add a to the result. This makes it possible to
rewrite the RPN into C<CDEF:result=a,b,c,d,e,+,+,+,+> which is
-evaluated differently:
+evaluated differently:
push value of variable a on the stack: a
push value of variable b on the stack: a b
and process it: S (where S == a+R)
As you can see the RPN expression C<a,b,c,d,e,+,+,+,+,+> will evaluate in
-C<((((d+e)+c)+b)+a)> and it has the same outcome as C<a,b,+,c,+,d,+,e,+>.
+C<((((d+e)+c)+b)+a)> and it has the same outcome as C<a,b,+,c,+,d,+,e,+>.
This is called the commutative law of addition,
but you may forget this right away, as long as you remember what it
means.
First in normal math: C<let result = a+b*c>. In this case you can't
choose the order yourself, you have to start with the multiplication
and then add a to it. You may alter the position of b and c, you must
-not alter the position of a and b.
+not alter the position of a and b.
You have to take this in consideration when converting this expression
into RPN. Read it as: "Add the outcome of b*c to a" and then it is
similar to one of the expressions in the previous paragraph, only the
multiplication and the addition changed places.
-When you have problems with RPN or when RRDtool is complaining, it's
+When you have problems with RPN or when RRDtool is complaining, it's
usually a good thing to write down the stack on a piece of paper
and see what happens. Have the manual ready and pretend to be RRDtool.
Just do all the math by hand to see what happens, I'm sure this will
where x represents "time>937521357"
where a represents the original value
where b represents the outcome of the previous example
-
+
time>937521357 --> TIME,937521357,GT
if (x) then a else b --> x,a,b,IF
=head2 Degrees Celsius vs. Degrees Fahrenheit
+To convert Celsius into Fahrenheit use the formula
+F=9/5*C+32
+
rrdtool graph demo.png --title="Demo Graph" \
DEF:cel=demo.rrd:exhaust:AVERAGE \
- CDEF:far=cel,32,-,0.55555,* \
+ CDEF:far=9,5,/,cel,*,32,+ \
LINE2:cel#00a000:"D. Celsius" \
LINE2:far#ff0000:"D. Fahrenheit\c"
and puts the values in variable "cel". The CDEF used is evaluated
as follows:
- CDEF:far=cel,32,-,0.5555,*
- 1. push variable "cel"
- 2. push 32
- 3. push function "minus" and process it
- The stack now contains values that are 32 less than "cel"
- 4. push 0.5555
- 5. push function "multiply" and process it
- 6. the resulting value is now "(cel-32)*0.55555"
-
-Note that if you take the Celsius to Fahrenheit function you should
-be doing "5/9*(cel-32)" so 0.55555 is not exactly correct. It is close
-enough for this purpose and it saves a calculation.
-
+ CDEF:far=9,5,/,cel,*,32,+
+ 1. push 9, push 5
+ 2. push function "divide" and process it
+ the stack now contains 9/5
+ 3. push variable "cel"
+ 4. push function "multiply" and process it
+ the stack now contains 9/5*cel
+ 5. push 32
+ 6. push function "plus" and process it
+ the stack contains now the temperature in Fahrenheit
+
=head2 Changing unknown into zero
rrdtool graph demo.png --title="Demo Graph" \
them when viewing what they do. Starting with the first CDEF we would
get:
- idat1,UN --> a
- 0 --> b
- idat1 --> c
+ idat1,UN --> a
+ 0 --> b
+ idat1 --> c
if (a) then (b) else (c)
The result is therefore "0" if it is true that "idat1" equals "UN".
the other half of your graph. This can be done in a relatively simple
way: what you need is the "wipeout" variable and place a negative
sign before it: "CDEF:wipeout2=wipeout,-1,*"
-
+
=head2 Filtering data
You may do some complex data filtering: