Code

Imported upstream version 1.3rc4.
[pkg-rrdtool.git] / doc / rrdgraph_rpn.html
1 <?xml version="1.0" ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <title>rrdgraph_rpn</title>
6 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
7 <link rev="made" href="mailto:root@localhost" />
8 </head>
10 <body style="background-color: white">
12 <p><a name="__index__"></a></p>
13 <!-- INDEX BEGIN -->
14 <!--
16 <ul>
18         <li><a href="#name">NAME</a></li>
19         <li><a href="#synopsis">SYNOPSIS</a></li>
20         <li><a href="#description">DESCRIPTION</a></li>
21         <li><a href="#operators">OPERATORS</a></li>
22         <li><a href="#variables">VARIABLES</a></li>
23         <li><a href="#see_also">SEE ALSO</a></li>
24         <li><a href="#author">AUTHOR</a></li>
25 </ul>
26 -->
27 <!-- INDEX END -->
29 <p>
30 </p>
31 <h1><a name="name">NAME</a></h1>
32 <p>rrdgraph_rpn - About RPN Math in rrdtool graph</p>
33 <p>
34 </p>
35 <hr />
36 <h1><a name="synopsis">SYNOPSIS</a></h1>
37 <p><em>RPN expression</em>:=<em>vname</em>|<em>operator</em>|<em>value</em>[,<em>RPN expression</em>]</p>
38 <p>
39 </p>
40 <hr />
41 <h1><a name="description">DESCRIPTION</a></h1>
42 <p>If you have ever used a traditional HP calculator you already know
43 <strong>RPN</strong>. The idea behind <strong>RPN</strong> is that you have a stack and push
44 your data onto this stack. Whenever you execute an operation, it
45 takes as many elements from the stack as needed. Pushing is done
46 implicitly, so whenever you specify a number or a variable, it gets
47 pushed onto the stack automatically.</p>
48 <p>At the end of the calculation there should be one and only one value left on
49 the stack.  This is the outcome of the function and this is what is put into
50 the <em>vname</em>.  For <strong>CDEF</strong> instructions, the stack is processed for each
51 data point on the graph. <strong>VDEF</strong> instructions work on an entire data set in
52 one run. Note, that currently <strong>VDEF</strong> instructions only support a limited
53 list of functions.</p>
54 <p>Example: <code>VDEF:maximum=mydata,MAXIMUM</code></p>
55 <p>This will set variable ``maximum'' which you now can use in the rest
56 of your RRD script.</p>
57 <p>Example: <code>CDEF:mydatabits=mydata,8,*</code></p>
58 <p>This means:  push variable <em>mydata</em>, push the number 8, execute
59 the operator <em>*</em>. The operator needs two elements and uses those
60 to return one value.  This value is then stored in <em>mydatabits</em>.
61 As you may have guessed, this instruction means nothing more than
62 <em>mydatabits = mydata * 8</em>.  The real power of <strong>RPN</strong> lies in the
63 fact that it is always clear in which order to process the input.
64 For expressions like <code>a = b + 3 * 5</code> you need to multiply 3 with
65 5 first before you add <em>b</em> to get <em>a</em>. However, with parentheses
66 you could change this order: <code>a = (b + 3) * 5</code>. In <strong>RPN</strong>, you
67 would do <code>a = b, 3, +, 5, *</code> without the need for parentheses.</p>
68 <p>
69 </p>
70 <hr />
71 <h1><a name="operators">OPERATORS</a></h1>
72 <dl>
73 <dt><strong><a name="item_boolean_operators">Boolean operators</a></strong>
75 <dd>
76 <p><strong>LT, LE, GT, GE, EQ, NE</strong></p>
77 </dd>
78 <dd>
79 <p>Pop two elements from the stack, compare them for the selected condition
80 and return 1 for true or 0 for false. Comparing an <em>unknown</em> or an
81 <em>infinite</em> value will always result in 0 (false).</p>
82 </dd>
83 <dd>
84 <p><strong>UN, ISINF</strong></p>
85 </dd>
86 <dd>
87 <p>Pop one element from the stack, compare this to <em>unknown</em> respectively
88 to <em>positive or negative infinity</em>. Returns 1 for true or 0 for false.</p>
89 </dd>
90 <dd>
91 <p><strong>IF</strong></p>
92 </dd>
93 <dd>
94 <p>Pops three elements from the stack.  If the element popped last is 0
95 (false), the value popped first is pushed back onto the stack,
96 otherwise the value popped second is pushed back. This does, indeed,
97 mean that any value other than 0 is considered to be true.</p>
98 </dd>
99 <dd>
100 <p>Example: <code>A,B,C,IF</code> should be read as <code>if (A) then (B) else (C)</code></p>
101 </dd>
102 <dd>
103 <p></p>
104 </dd>
105 </li>
106 <dt><strong><a name="item_comparing_values">Comparing values</a></strong>
108 <dd>
109 <p><strong>MIN, MAX</strong></p>
110 </dd>
111 <dd>
112 <p>Pops two elements from the stack and returns the smaller or larger,
113 respectively.  Note that <em>infinite</em> is larger than anything else.
114 If one of the input numbers is <em>unknown</em> then the result of the operation will be
115 <em>unknown</em> too.</p>
116 </dd>
117 <dd>
118 <p><strong>LIMIT</strong></p>
119 </dd>
120 <dd>
121 <p>Pops two elements from the stack and uses them to define a range.
122 Then it pops another element and if it falls inside the range, it
123 is pushed back. If not, an <em>unknown</em> is pushed.</p>
124 </dd>
125 <dd>
126 <p>The range defined includes the two boundaries (so: a number equal
127 to one of the boundaries will be pushed back). If any of the three
128 numbers involved is either <em>unknown</em> or <em>infinite</em> this function
129 will always return an <em>unknown</em></p>
130 </dd>
131 <dd>
132 <p>Example: <code>CDEF:a=alpha,0,100,LIMIT</code> will return <em>unknown</em> if
133 alpha is lower than 0 or if it is higher than 100.</p>
134 </dd>
135 <dd>
136 <p></p>
137 </dd>
138 </li>
139 <dt><strong><a name="item_arithmetics">Arithmetics</a></strong>
141 <dd>
142 <p><strong>+, -, *, /, %</strong></p>
143 </dd>
144 <dd>
145 <p>Add, subtract, multiply, divide, modulo</p>
146 </dd>
147 <dd>
148 <p><strong>ADDNAN</strong></p>
149 </dd>
150 <dd>
151 <p>NAN-safe addition. If one parameter is NAN/UNKNOWN it'll be treated as
152 zero. If both parameters are NAN/UNKNOWN, NAN/UNKNOWN will be returned.</p>
153 </dd>
154 <dd>
155 <p><strong>SIN, COS, LOG, EXP, SQRT</strong></p>
156 </dd>
157 <dd>
158 <p>Sine and cosine (input in radians), log and exp (natural logarithm),
159 square root.</p>
160 </dd>
161 <dd>
162 <p><strong>ATAN</strong></p>
163 </dd>
164 <dd>
165 <p>Arctangent (output in radians).</p>
166 </dd>
167 <dd>
168 <p><strong>ATAN2</strong></p>
169 </dd>
170 <dd>
171 <p>Arctangent of y,x components (output in radians).
172 This pops one element from the stack, the x (cosine) component, and then
173 a second, which is the y (sine) component.
174 It then pushes the arctangent of their ratio, resolving the ambiguity between
175 quadrants.</p>
176 </dd>
177 <dd>
178 <p>Example: <code>CDEF:angle=Y,X,ATAN2,RAD2DEG</code> will convert <code>X,Y</code>
179 components into an angle in degrees.</p>
180 </dd>
181 <dd>
182 <p><strong>FLOOR, CEIL</strong></p>
183 </dd>
184 <dd>
185 <p>Round down or up to the nearest integer.</p>
186 </dd>
187 <dd>
188 <p><strong>DEG2RAD, RAD2DEG</strong></p>
189 </dd>
190 <dd>
191 <p>Convert angle in degrees to radians, or radians to degrees.</p>
192 </dd>
193 <dd>
194 <p><strong>ABS</strong></p>
195 </dd>
196 <dd>
197 <p>Take the absolute value.</p>
198 </dd>
199 </li>
200 <dt><strong><a name="item_set_operations">Set Operations</a></strong>
202 <dd>
203 <p><strong>SORT, REV</strong></p>
204 </dd>
205 <dd>
206 <p>Pop one element from the stack.  This is the <em>count</em> of items to be sorted
207 (or reversed).  The top <em>count</em> of the remaining elements are then sorted
208 (or reversed) in place on the stack.</p>
209 </dd>
210 <dd>
211 <p>Example: <code>CDEF:x=v1,v2,v3,v4,v5,v6,6,SORT,POP,5,REV,POP,+,+,+,4,/</code> will
212 compute the average of the values v1 to v6 after removing the smallest and
213 largest.</p>
214 </dd>
215 <dd>
216 <p><strong>AVG</strong></p>
217 </dd>
218 <dd>
219 <p>Pop one element (<em>count</em>) from the stack. Now pop <em>count</em> elements and build the
220 average, ignoring all UNKNOWN values in the process.</p>
221 </dd>
222 <dd>
223 <p>Example: <code>CDEF:x=a,b,c,d,4,AVG</code></p>
224 </dd>
225 <dd>
226 <p><strong>TREND, TRENDNAN</strong></p>
227 </dd>
228 <dd>
229 <p>Create a ``sliding window'' average of another data series.</p>
230 </dd>
231 <dd>
232 <p>Usage:
233 CDEF:smoothed=x,1800,TREND</p>
234 </dd>
235 <dd>
236 <p>This will create a half-hour (1800 second) sliding window average of x.  The
237 average is essentially computed as shown here:</p>
238 </dd>
239 <dd>
240 <pre>
241                  +---!---!---!---!---!---!---!---!---&gt;
242                                                      now
243                        delay     t0
244                  &lt;---------------&gt;
245                          delay       t1
246                      &lt;---------------&gt;
247                               delay      t2
248                          &lt;---------------&gt;</pre>
249 </dd>
250 <dd>
251 <pre>
252      Value at sample (t0) will be the average between (t0-delay) and (t0)
253      Value at sample (t1) will be the average between (t1-delay) and (t1)
254      Value at sample (t2) will be the average between (t2-delay) and (t2)</pre>
255 </dd>
256 <dd>
257 <p>TRENDNAN is - in contrast to TREND - NAN-safe. If you use TREND and one 
258 source value is NAN the complete sliding window is affected. The TRENDNAN 
259 operation ignores all NAN-values in a sliding window and computes the 
260 average of the remaining values.</p>
261 </dd>
262 </li>
263 <dt><strong><a name="item_special_values">Special values</a></strong>
265 <dd>
266 <p><strong>UNKN</strong></p>
267 </dd>
268 <dd>
269 <p>Pushes an unknown value on the stack</p>
270 </dd>
271 <dd>
272 <p><strong>INF, NEGINF</strong></p>
273 </dd>
274 <dd>
275 <p>Pushes a positive or negative infinite value on the stack. When
276 such a value is graphed, it appears at the top or bottom of the
277 graph, no matter what the actual value on the y-axis is.</p>
278 </dd>
279 <dd>
280 <p><strong>PREV</strong></p>
281 </dd>
282 <dd>
283 <p>Pushes an <em>unknown</em> value if this is the first value of a data
284 set or otherwise the result of this <strong>CDEF</strong> at the previous time
285 step. This allows you to do calculations across the data.  This
286 function cannot be used in <strong>VDEF</strong> instructions.</p>
287 </dd>
288 <dd>
289 <p><strong>PREV(vname)</strong></p>
290 </dd>
291 <dd>
292 <p>Pushes an <em>unknown</em> value if this is the first value of a data
293 set or otherwise the result of the vname variable at the previous time
294 step. This allows you to do calculations across the data. This
295 function cannot be used in <strong>VDEF</strong> instructions.</p>
296 </dd>
297 <dd>
298 <p><strong>COUNT</strong></p>
299 </dd>
300 <dd>
301 <p>Pushes the number 1 if this is the first value of the data set, the
302 number 2 if it is the second, and so on. This special value allows
303 you to make calculations based on the position of the value within
304 the data set. This function cannot be used in <strong>VDEF</strong> instructions.</p>
305 </dd>
306 </li>
307 <dt><strong><a name="item_time">Time</a></strong>
309 <dd>
310 <p>Time inside RRDtool is measured in seconds since the epoch. The
311 epoch is defined to be <code>Thu&nbsp;Jan&nbsp;&nbsp;1&nbsp;00:00:00&nbsp;UTC&nbsp;1970</code>.</p>
312 </dd>
313 <dd>
314 <p><strong>NOW</strong></p>
315 </dd>
316 <dd>
317 <p>Pushes the current time on the stack.</p>
318 </dd>
319 <dd>
320 <p><strong>TIME</strong></p>
321 </dd>
322 <dd>
323 <p>Pushes the time the currently processed value was taken at onto the stack.</p>
324 </dd>
325 <dd>
326 <p><strong>LTIME</strong></p>
327 </dd>
328 <dd>
329 <p>Takes the time as defined by <strong>TIME</strong>, applies the time zone offset
330 valid at that time including daylight saving time if your OS supports
331 it, and pushes the result on the stack.  There is an elaborate example
332 in the examples section below on how to use this.</p>
333 </dd>
334 </li>
335 <dt><strong><a name="item_processing_the_stack_directly">Processing the stack directly</a></strong>
337 <dd>
338 <p><strong>DUP, POP, EXC</strong></p>
339 </dd>
340 <dd>
341 <p>Duplicate the top element, remove the top element, exchange the two
342 top elements.</p>
343 </dd>
344 <dd>
345 <p></p>
346 </dd>
347 </li>
348 </dl>
349 <p>
350 </p>
351 <hr />
352 <h1><a name="variables">VARIABLES</a></h1>
353 <p>These operators work only on <strong>VDEF</strong> statements. Note that currently ONLY these work for <strong>VDEF</strong>.</p>
354 <dl>
355 <dt><strong><a name="item_maximum_2c_minimum_2c_average">MAXIMUM, MINIMUM, AVERAGE</a></strong>
357 <dd>
358 <p>Return the corresponding value, MAXIMUM and MINIMUM also return
359 the first occurrence of that value in the time component.</p>
360 </dd>
361 <dd>
362 <p>Example: <code>VDEF:avg=mydata,AVERAGE</code></p>
363 </dd>
364 </li>
365 <dt><strong><a name="item_stdev">STDEV</a></strong>
367 <dd>
368 <p>Returns the standard deviation of the values.</p>
369 </dd>
370 <dd>
371 <p>Example: <code>VDEF:stdev=mydata,STDEV</code></p>
372 </dd>
373 </li>
374 <dt><strong><a name="item_last_2c_first">LAST, FIRST</a></strong>
376 <dd>
377 <p>Return the last/first value including its time.  The time for
378 FIRST is actually the start of the corresponding interval, whereas
379 LAST returns the end of the corresponding interval.</p>
380 </dd>
381 <dd>
382 <p>Example: <code>VDEF:first=mydata,FIRST</code></p>
383 </dd>
384 </li>
385 <dt><strong><a name="item_total">TOTAL</a></strong>
387 <dd>
388 <p>Returns the rate from each defined time slot multiplied with the
389 step size.  This can, for instance, return total bytes transfered
390 when you have logged bytes per second. The time component returns
391 the number of seconds.</p>
392 </dd>
393 <dd>
394 <p>Example: <code>VDEF:total=mydata,TOTAL</code></p>
395 </dd>
396 </li>
397 <dt><strong><a name="item_percent">PERCENT</a></strong>
399 <dd>
400 <p>This should follow a <strong>DEF</strong> or <strong>CDEF</strong> <em>vname</em>. The <em>vname</em> is popped,
401 another number is popped which is a certain percentage (0..100). The
402 data set is then sorted and the value returned is chosen such that
403 <em>percentage</em> percent of the values is lower or equal than the result.
404 <em>Unknown</em> values are considered lower than any finite number for this
405 purpose so if this operator returns an <em>unknown</em> you have quite a lot
406 of them in your data.  <strong>Inf</strong>inite numbers are lesser, or more, than the
407 finite numbers and are always more than the <em>Unknown</em> numbers.
408 (NaN &lt; -INF &lt; finite values &lt; INF)</p>
409 </dd>
410 <dd>
411 <p>Example: <code>VDEF:perc95=mydata,95,PERCENT</code></p>
412 </dd>
413 </li>
414 <dt><strong><a name="item_lslslope_2c_lslint_2c_lslcorrel">LSLSLOPE, LSLINT, LSLCORREL</a></strong>
416 <dd>
417 <p>Return the parameters for a <strong>L</strong>east <strong>S</strong>quares <strong>L</strong>ine <em>(y = mx +b)</em> 
418 which approximate the provided dataset.  LSLSLOPE is the slope <em>(m)</em> of
419 the line related to the COUNT position of the data.  LSLINT is the 
420 y-intercept <em>(b)</em>, which happens also to be the first data point on the 
421 graph. LSLCORREL is the Correlation Coefficient (also know as Pearson's 
422 Product Moment Correlation Coefficient).  It will range from 0 to +/-1 
423 and represents the quality of fit for the approximation.</p>
424 </dd>
425 <dd>
426 <p>Example: <code>VDEF:slope=mydata,LSLSLOPE</code></p>
427 </dd>
428 </li>
429 </dl>
430 <p>
431 </p>
432 <hr />
433 <h1><a name="see_also">SEE ALSO</a></h1>
434 <p><a href="././rrdgraph.html">the rrdgraph manpage</a> gives an overview of how <strong>rrdtool graph</strong> works.
435 <a href="././rrdgraph_data.html">the rrdgraph_data manpage</a> describes <strong>DEF</strong>,<strong>CDEF</strong> and <strong>VDEF</strong> in detail.
436 <a href="././rrdgraph_rpn.html">the rrdgraph_rpn manpage</a> describes the <strong>RPN</strong> language used in the <strong>?DEF</strong> statements.
437 <a href="././rrdgraph_graph.html">the rrdgraph_graph manpage</a> page describes all of the graph and print functions.</p>
438 <p>Make sure to read <a href="././rrdgraph_examples.html">the rrdgraph_examples manpage</a> for tips&amp;tricks.</p>
439 <p>
440 </p>
441 <hr />
442 <h1><a name="author">AUTHOR</a></h1>
443 <p>Program by Tobias Oetiker &lt;<a href="mailto:tobi@oetiker.ch">tobi@oetiker.ch</a>&gt;</p>
444 <p>This manual page by Alex van den Bogaerdt &lt;<a href="mailto:alex@ergens.op.het.net">alex@ergens.op.het.net</a>&gt;</p>
446 </body>
448 </html>