Code

Imported upstream version 1.3rc9.
[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></dt>
75 <dd>
76 <p><strong>LT, LE, GT, GE, EQ, NE</strong></p>
77 <p>Pop two elements from the stack, compare them for the selected condition
78 and return 1 for true or 0 for false. Comparing an <em>unknown</em> or an
79 <em>infinite</em> value will always result in 0 (false).</p>
80 <p><strong>UN, ISINF</strong></p>
81 <p>Pop one element from the stack, compare this to <em>unknown</em> respectively
82 to <em>positive or negative infinity</em>. Returns 1 for true or 0 for false.</p>
83 <p><strong>IF</strong></p>
84 <p>Pops three elements from the stack.  If the element popped last is 0
85 (false), the value popped first is pushed back onto the stack,
86 otherwise the value popped second is pushed back. This does, indeed,
87 mean that any value other than 0 is considered to be true.</p>
88 <p>Example: <code>A,B,C,IF</code> should be read as <code>if (A) then (B) else (C)</code></p>
89 <p></p>
90 </dd>
91 <dt><strong><a name="item_comparing_values">Comparing values</a></strong></dt>
93 <dd>
94 <p><strong>MIN, MAX</strong></p>
95 <p>Pops two elements from the stack and returns the smaller or larger,
96 respectively.  Note that <em>infinite</em> is larger than anything else.
97 If one of the input numbers is <em>unknown</em> then the result of the operation will be
98 <em>unknown</em> too.</p>
99 <p><strong>LIMIT</strong></p>
100 <p>Pops two elements from the stack and uses them to define a range.
101 Then it pops another element and if it falls inside the range, it
102 is pushed back. If not, an <em>unknown</em> is pushed.</p>
103 <p>The range defined includes the two boundaries (so: a number equal
104 to one of the boundaries will be pushed back). If any of the three
105 numbers involved is either <em>unknown</em> or <em>infinite</em> this function
106 will always return an <em>unknown</em></p>
107 <p>Example: <code>CDEF:a=alpha,0,100,LIMIT</code> will return <em>unknown</em> if
108 alpha is lower than 0 or if it is higher than 100.</p>
109 <p></p>
110 </dd>
111 <dt><strong><a name="item_arithmetics">Arithmetics</a></strong></dt>
113 <dd>
114 <p><strong>+, -, *, /, %</strong></p>
115 <p>Add, subtract, multiply, divide, modulo</p>
116 <p><strong>ADDNAN</strong></p>
117 <p>NAN-safe addition. If one parameter is NAN/UNKNOWN it'll be treated as
118 zero. If both parameters are NAN/UNKNOWN, NAN/UNKNOWN will be returned.</p>
119 <p><strong>SIN, COS, LOG, EXP, SQRT</strong></p>
120 <p>Sine and cosine (input in radians), log and exp (natural logarithm),
121 square root.</p>
122 <p><strong>ATAN</strong></p>
123 <p>Arctangent (output in radians).</p>
124 <p><strong>ATAN2</strong></p>
125 <p>Arctangent of y,x components (output in radians).
126 This pops one element from the stack, the x (cosine) component, and then
127 a second, which is the y (sine) component.
128 It then pushes the arctangent of their ratio, resolving the ambiguity between
129 quadrants.</p>
130 <p>Example: <code>CDEF:angle=Y,X,ATAN2,RAD2DEG</code> will convert <code>X,Y</code>
131 components into an angle in degrees.</p>
132 <p><strong>FLOOR, CEIL</strong></p>
133 <p>Round down or up to the nearest integer.</p>
134 <p><strong>DEG2RAD, RAD2DEG</strong></p>
135 <p>Convert angle in degrees to radians, or radians to degrees.</p>
136 <p><strong>ABS</strong></p>
137 <p>Take the absolute value.</p>
138 </dd>
139 <dt><strong><a name="item_set_operations">Set Operations</a></strong></dt>
141 <dd>
142 <p><strong>SORT, REV</strong></p>
143 <p>Pop one element from the stack.  This is the <em>count</em> of items to be sorted
144 (or reversed).  The top <em>count</em> of the remaining elements are then sorted
145 (or reversed) in place on the stack.</p>
146 <p>Example: <code>CDEF:x=v1,v2,v3,v4,v5,v6,6,SORT,POP,5,REV,POP,+,+,+,4,/</code> will
147 compute the average of the values v1 to v6 after removing the smallest and
148 largest.</p>
149 <p><strong>AVG</strong></p>
150 <p>Pop one element (<em>count</em>) from the stack. Now pop <em>count</em> elements and build the
151 average, ignoring all UNKNOWN values in the process.</p>
152 <p>Example: <code>CDEF:x=a,b,c,d,4,AVG</code></p>
153 <p><strong>TREND, TRENDNAN</strong></p>
154 <p>Create a ``sliding window'' average of another data series.</p>
155 <p>Usage:
156 CDEF:smoothed=x,1800,TREND</p>
157 <p>This will create a half-hour (1800 second) sliding window average of x.  The
158 average is essentially computed as shown here:</p>
159 <pre>
160                  +---!---!---!---!---!---!---!---!---&gt;
161                                                      now
162                        delay     t0
163                  &lt;---------------&gt;
164                          delay       t1
165                      &lt;---------------&gt;
166                               delay      t2
167                          &lt;---------------&gt;</pre>
168 <pre>
169      Value at sample (t0) will be the average between (t0-delay) and (t0)
170      Value at sample (t1) will be the average between (t1-delay) and (t1)
171      Value at sample (t2) will be the average between (t2-delay) and (t2)</pre>
172 <p>TRENDNAN is - in contrast to TREND - NAN-safe. If you use TREND and one 
173 source value is NAN the complete sliding window is affected. The TRENDNAN 
174 operation ignores all NAN-values in a sliding window and computes the 
175 average of the remaining values.</p>
176 </dd>
177 <dt><strong><a name="item_special_values">Special values</a></strong></dt>
179 <dd>
180 <p><strong>UNKN</strong></p>
181 <p>Pushes an unknown value on the stack</p>
182 <p><strong>INF, NEGINF</strong></p>
183 <p>Pushes a positive or negative infinite value on the stack. When
184 such a value is graphed, it appears at the top or bottom of the
185 graph, no matter what the actual value on the y-axis is.</p>
186 <p><strong>PREV</strong></p>
187 <p>Pushes an <em>unknown</em> value if this is the first value of a data
188 set or otherwise the result of this <strong>CDEF</strong> at the previous time
189 step. This allows you to do calculations across the data.  This
190 function cannot be used in <strong>VDEF</strong> instructions.</p>
191 <p><strong>PREV(vname)</strong></p>
192 <p>Pushes an <em>unknown</em> value if this is the first value of a data
193 set or otherwise the result of the vname variable at the previous time
194 step. This allows you to do calculations across the data. This
195 function cannot be used in <strong>VDEF</strong> instructions.</p>
196 <p><strong>COUNT</strong></p>
197 <p>Pushes the number 1 if this is the first value of the data set, the
198 number 2 if it is the second, and so on. This special value allows
199 you to make calculations based on the position of the value within
200 the data set. This function cannot be used in <strong>VDEF</strong> instructions.</p>
201 </dd>
202 <dt><strong><a name="item_time">Time</a></strong></dt>
204 <dd>
205 <p>Time inside RRDtool is measured in seconds since the epoch. The
206 epoch is defined to be <code>Thu&nbsp;Jan&nbsp;&nbsp;1&nbsp;00:00:00&nbsp;UTC&nbsp;1970</code>.</p>
207 <p><strong>NOW</strong></p>
208 <p>Pushes the current time on the stack.</p>
209 <p><strong>TIME</strong></p>
210 <p>Pushes the time the currently processed value was taken at onto the stack.</p>
211 <p><strong>LTIME</strong></p>
212 <p>Takes the time as defined by <strong>TIME</strong>, applies the time zone offset
213 valid at that time including daylight saving time if your OS supports
214 it, and pushes the result on the stack.  There is an elaborate example
215 in the examples section below on how to use this.</p>
216 </dd>
217 <dt><strong><a name="item_processing_the_stack_directly">Processing the stack directly</a></strong></dt>
219 <dd>
220 <p><strong>DUP, POP, EXC</strong></p>
221 <p>Duplicate the top element, remove the top element, exchange the two
222 top elements.</p>
223 <p></p>
224 </dd>
225 </dl>
226 <p>
227 </p>
228 <hr />
229 <h1><a name="variables">VARIABLES</a></h1>
230 <p>These operators work only on <strong>VDEF</strong> statements. Note that currently ONLY these work for <strong>VDEF</strong>.</p>
231 <dl>
232 <dt><strong><a name="item_maximum_2c_minimum_2c_average">MAXIMUM, MINIMUM, AVERAGE</a></strong></dt>
234 <dd>
235 <p>Return the corresponding value, MAXIMUM and MINIMUM also return
236 the first occurrence of that value in the time component.</p>
237 <p>Example: <code>VDEF:avg=mydata,AVERAGE</code></p>
238 </dd>
239 <dt><strong><a name="item_stdev">STDEV</a></strong></dt>
241 <dd>
242 <p>Returns the standard deviation of the values.</p>
243 <p>Example: <code>VDEF:stdev=mydata,STDEV</code></p>
244 </dd>
245 <dt><strong><a name="item_last_2c_first">LAST, FIRST</a></strong></dt>
247 <dd>
248 <p>Return the last/first value including its time.  The time for
249 FIRST is actually the start of the corresponding interval, whereas
250 LAST returns the end of the corresponding interval.</p>
251 <p>Example: <code>VDEF:first=mydata,FIRST</code></p>
252 </dd>
253 <dt><strong><a name="item_total">TOTAL</a></strong></dt>
255 <dd>
256 <p>Returns the rate from each defined time slot multiplied with the
257 step size.  This can, for instance, return total bytes transfered
258 when you have logged bytes per second. The time component returns
259 the number of seconds.</p>
260 <p>Example: <code>VDEF:total=mydata,TOTAL</code></p>
261 </dd>
262 <dt><strong><a name="item_percent">PERCENT</a></strong></dt>
264 <dd>
265 <p>This should follow a <strong>DEF</strong> or <strong>CDEF</strong> <em>vname</em>. The <em>vname</em> is popped,
266 another number is popped which is a certain percentage (0..100). The
267 data set is then sorted and the value returned is chosen such that
268 <em>percentage</em> percent of the values is lower or equal than the result.
269 <em>Unknown</em> values are considered lower than any finite number for this
270 purpose so if this operator returns an <em>unknown</em> you have quite a lot
271 of them in your data.  <strong>Inf</strong>inite numbers are lesser, or more, than the
272 finite numbers and are always more than the <em>Unknown</em> numbers.
273 (NaN &lt; -INF &lt; finite values &lt; INF)</p>
274 <p>Example: <code>VDEF:perc95=mydata,95,PERCENT</code></p>
275 </dd>
276 <dt><strong><a name="item_lslslope_2c_lslint_2c_lslcorrel">LSLSLOPE, LSLINT, LSLCORREL</a></strong></dt>
278 <dd>
279 <p>Return the parameters for a <strong>L</strong>east <strong>S</strong>quares <strong>L</strong>ine <em>(y = mx +b)</em> 
280 which approximate the provided dataset.  LSLSLOPE is the slope <em>(m)</em> of
281 the line related to the COUNT position of the data.  LSLINT is the 
282 y-intercept <em>(b)</em>, which happens also to be the first data point on the 
283 graph. LSLCORREL is the Correlation Coefficient (also know as Pearson's 
284 Product Moment Correlation Coefficient).  It will range from 0 to +/-1 
285 and represents the quality of fit for the approximation.</p>
286 <p>Example: <code>VDEF:slope=mydata,LSLSLOPE</code></p>
287 </dd>
288 </dl>
289 <p>
290 </p>
291 <hr />
292 <h1><a name="see_also">SEE ALSO</a></h1>
293 <p><a href="././rrdgraph.html">the rrdgraph manpage</a> gives an overview of how <strong>rrdtool graph</strong> works.
294 <a href="././rrdgraph_data.html">the rrdgraph_data manpage</a> describes <strong>DEF</strong>,<strong>CDEF</strong> and <strong>VDEF</strong> in detail.
295 <a href="././rrdgraph_rpn.html">the rrdgraph_rpn manpage</a> describes the <strong>RPN</strong> language used in the <strong>?DEF</strong> statements.
296 <a href="././rrdgraph_graph.html">the rrdgraph_graph manpage</a> page describes all of the graph and print functions.</p>
297 <p>Make sure to read <a href="././rrdgraph_examples.html">the rrdgraph_examples manpage</a> for tips&amp;tricks.</p>
298 <p>
299 </p>
300 <hr />
301 <h1><a name="author">AUTHOR</a></h1>
302 <p>Program by Tobias Oetiker &lt;<a href="mailto:tobi@oetiker.ch">tobi@oetiker.ch</a>&gt;</p>
303 <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>
305 </body>
307 </html>