missing documentation ... -- Alex van den Bogaerdt <alex@slot.hollandcasino.nl>
[rrdtool.git] / doc / rrdgraph_rpn.pod
1 =head1 NAME
2
3 rrdtool graph - Round Robin Database tool grapher functions
4
5 WARNING: This is for version 1.1.x which is B<I<BETA>> software.
6 The software may contain serious bugs. Some of the items
7 described in here may not yet exist (although this should
8 be mentioned) or still be in the alpha stage.  As with every
9 other RRDtool release: use at your own risk.  In contrast with
10 the stable version of RRDtool, this release may contain bugs
11 known to the authors.  It is highly recommended that you subscribe
12 to the mailing list.
13
14 =head1 SYNOPSYS
15
16 I<E<lt>RPN expressionE<gt>> := 
17 I<E<lt>vnameE<gt>>|I<E<lt>operatorE<gt>>|I<E<lt>valueE<gt>>
18 [ , I<E<lt>RPN expressionE<gt>>]
19
20 =head1 DESCRIPTION
21
22 If you have ever used a traditional HP calculator you already know
23 B<RPN>. The idea behind B<RPN> is that you have a stack and push
24 your data onto this stack. Whenever you execute an operation, it
25 takes as many elements from the stack as needed. Pushing is done
26 implicit so whenever you specify a number or a variable, it gets
27 pushed automatically.
28
29 At the end of the calculation there should be one and exactly one
30 value left on the stack.  This is the outcome of the function and
31 this is what is put into the I<vname>.  For B<CDEF> instructions,
32 the stack is processed for each data point on the graph. B<VDEF>
33 instructions work on an entire data set in one run.
34
35 Example: C<CDEF:mydatabits=mydata,8,*>
36
37 This means:  push variable I<mydata>, push the number 8, execute
38 the operator I<+>. The operator needs two elements and uses those
39 to return one value.  This value is then stored in I<mydatabits>.
40 As you may have guessed, this instruction means nothing more than
41 I<mydatabits = mydata * 8>.  The real power of B<RPN> lies in the
42 fact that it is always clear in which order to process the input.
43 For expressions like C<a = b + 3 * 5> you need to multiply 3 with
44 5 first before you add I<b> to get I<a>. However, with parentheses
45 you could change this order: C<a = (b + 3) * 5>. In B<RPN>, you
46 would do C<a = b, 3, +, 5, *> and need no parentheses.
47
48 =head1 OPERATORS
49
50 =over 4
51
52 =item Boolean operators
53
54 B<LT, LE, GT, GE, EQ, NE>
55
56 I<Note: NE is not yet implemented>
57
58 Pop two elements from the stack, compare them for the selected condition
59 and return 1 for true or 0 for false. Comparing an I<unknown> or an
60 I<infinite> value will always result in 0 (false).
61
62 B<UN, ISINF>
63
64 I<Note: ISINF is not yet implemented>
65
66 Pop one element from the stack, compare this to I<unknown> respectively
67 to I<positive or negative infinity>. Returns 1 for true or 0 for false.
68
69 B<IF>
70
71 Pops three elements from the stack.  If the last element is 0 (false),
72 the first value is pushed back onto the stack, otherwise the second
73 popped value is pushed back. This does, indeed, mean that any value
74 other than 0 is considered true.
75 I<Note: Should this change? It should IMHO as all the other functions
76 would return unknown if A,B or C were unknown>
77
78 Example: C<A,B,C,IF> should be read as C<if (A) then (B) else (C)>
79
80 Z<>
81
82 =item Comparing values
83
84 B<MIN, MAX> 
85
86 Pops two elements from the stack and returns the lesser or larger.
87 The two numbers shouldn't be I<infinite> or I<unknown>, if they are
88 that value is pushed back onto the stack as the result.
89
90 B<LIMIT>
91
92 Pops two elements from the stack and uses them to define a range.
93 Then it pops another element and if it falls inside the range, it
94 is pushed back. If not, an I<unknown> is pushed.
95
96 The range defined includes the two boundaries (so: a number equal
97 to one of the boundaries will be pushed back). If any of the three
98 numbers involved is either I<unknown> or I<infinite> this function
99 will always return an I<unknown>
100
101 Example: C<CDEF:a=alpha,0,100,LIMIT> will return I<unknown> if
102 alpha is lower than 0 or if it is higher than 100.
103
104 Z<>
105
106 =item Arithmetics
107
108 B<+, -, *, /, %>
109
110 Add, subtract, multiply, divide, modulo
111
112 B<SIN, COS, LOG, EXP>
113
114 Sine, cosine (input in radians), log, exp (natural logarithm)
115
116 B<FLOOR, CEIL>
117
118 Round down,up to the nearest integer
119
120 Z<>
121
122 =item Special values
123
124 B<UNKN>
125
126 Pushes an unknown value on the stack
127
128 B<INF, NEGINF>
129
130 Pushes a positive or negative infinite value on the stack. When
131 such a value is graphed, it appears at the top or bottom of the
132 graph, no matter what the actual value on the y-axis is.
133
134 B<PREV>
135
136 Pushes an I<unknown> value if this is the first value of a data
137 set or otherwise the result of this B<CDEF> at the previous time
138 step. This allows you to do calculations across the data.  This
139 function cannot be used in B<VDEF> instructions.
140
141 Z<>
142
143 =item Time
144
145 Time inside RRDtool is measured in seconds since the epoch. This
146 epoch is defined to be S<C<Thu Jan  1 00:00:00 UTC 1970>>.
147
148 Z<>
149
150 =over 4
151
152 =item NOW
153
154 Pushes the current time on the stack.
155
156 Z<>
157
158 =item TIME
159
160 Pushes the time the currently processed value was taken onto the stack.
161
162 Z<>
163
164 =item LTIME
165
166 Takes the time as defined by B<TIME>, applies the time zone offset
167 valid at that time including daylight saving time if your OS supports
168 it, and pushes the result on the stack.  There is an elaborate example
169 in the examples section on how to use this.
170
171 =back
172
173 For B<VDEF> operations, B<TIME> and B<LTIME> have a different meaning
174 I<not yet implemented>.  As the B<VDEF> statement does not work per
175 value but rather on a complete time series, there is no such thing as
176 the currently processed value.  However, if you have used an operator
177 that returned a time component and would like to have this available
178 in the value component in stead (so you can use it as a number), you
179 can use B<TIME> or B<LTIME> for that.
180
181 Z<>
182
183 =item Processing the stack directly
184
185 B<DUP, POP, EXC>
186
187 Duplicate the top element, remove the top element, exchange the two
188 top elements.
189
190 Z<>
191
192 =item Selecting characteristics
193
194 These operators work only on B<VDEF> statements.
195 I<We can make most of them work at DEF and CDEF statements. If we do
196 so, we have a moving (not rolling!) average, max,min etcetera>
197
198 Z<>
199
200 =over 4
201
202 =item MAXIMUM, MINIMUM, AVERAGE
203
204 Return the corresponding value
205
206 Z<>
207
208 =item LAST, FIRST
209
210 Return the last,first value including its time 
211
212 Z<>
213
214 =item PERCENT
215
216 Should follow a B<DEF> or B<CDEF> I<vname>. This I<vname> is popped,
217 another number is popped which is a certain percentage (0..100). The
218 data set is then sorted and the value returned is chosen such that
219 I<percentage> percent of the values is lower or equal than the result.
220 I<Unknown> values are considered lower than any finite number for this
221 purpose so if this operator returns an I<unknown> you have quite a lot
222 of them in your data.  I<Inf>inite numbers are lesser, or more, than the
223 finite numbers and are always more than the I<Unknown> numbers.
224
225 Example: C<VDEF:perc95=mydata,95,PERCENT>
226
227 =back
228
229 =back
230
231 =head1 SEE ALSO
232
233 L<rrdgraph> gives an overview of how B<rrdtool graph> works.
234 L<rrdgraph_data> describes B<DEF>,B<CDEF> and B<VDEF> in detail,
235 L<rrdgraph_rpn> describes the B<RPN> language used in the B<?DEF> statements,
236 L<rrdgraph_graph> page describes all of the graph and print functions.
237
238 Make sure to read L<rrdgraph_examples> for tipsE<amp>tricks.
239
240 =head1 AUTHOR
241
242 Program by Tobias Oetiker E<lt>oetiker@ee.ethz.chE<gt>
243
244 This manual page by Alex van den Bogaerdt E<lt>alex@ergens.op.het.netE<gt>