Code

327dc0d6629813faf8ab0f71d0e026160f6f20a6
[pkg-rrdtool.git] / doc / rrdgraph_rpn.txt
1 RRDGRAPH_RPN(1)                     rrdtool                    RRDGRAPH_RPN(1)
5 N\bNA\bAM\bME\bE
6        rrdgraph_rpn - About RPN Math in rrdtool graph
8 S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS
9        _\bR_\bP_\bN _\be_\bx_\bp_\br_\be_\bs_\bs_\bi_\bo_\bn:=_\bv_\bn_\ba_\bm_\be|_\bo_\bp_\be_\br_\ba_\bt_\bo_\br|_\bv_\ba_\bl_\bu_\be[,_\bR_\bP_\bN _\be_\bx_\bp_\br_\be_\bs_\bs_\bi_\bo_\bn]
11 D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
12        If you have ever used a traditional HP calculator you already know R\bRP\bPN\bN
13        (Reverse Polish Notation).  The idea behind R\bRP\bPN\bN is that you have a
14        stack and push your data onto this stack. Whenever you execute an oper-
15        ation, it takes as many elements from the stack as needed. Pushing is
16        done implicitly, so whenever you specify a number or a variable, it
17        gets pushed onto the stack automatically.
19        At the end of the calculation there should be one and only one value
20        left on the stack.  This is the outcome of the function and this is
21        what is put into the _\bv_\bn_\ba_\bm_\be.  For C\bCD\bDE\bEF\bF instructions, the stack is pro-
22        cessed for each data point on the graph. V\bVD\bDE\bEF\bF instructions work on an
23        entire data set in one run. Note, that currently V\bVD\bDE\bEF\bF instructions only
24        support a limited list of functions.
26        Example: "VDEF:maximum=mydata,MAXIMUM"
28        This will set variable "maximum" which you now can use in the rest of
29        your RRD script.
31        Example: "CDEF:mydatabits=mydata,8,*"
33        This means:  push variable _\bm_\by_\bd_\ba_\bt_\ba, push the number 8, execute the oper-
34        ator _\b*. The operator needs two elements and uses those to return one
35        value.  This value is then stored in _\bm_\by_\bd_\ba_\bt_\ba_\bb_\bi_\bt_\bs.  As you may have
36        guessed, this instruction means nothing more than _\bm_\by_\bd_\ba_\bt_\ba_\bb_\bi_\bt_\bs _\b= _\bm_\by_\bd_\ba_\bt_\ba _\b*
37        _\b8.  The real power of R\bRP\bPN\bN lies in the fact that it is always clear in
38        which order to process the input.  For expressions like "a = b + 3 * 5"
39        you need to multiply 3 with 5 first before you add _\bb to get _\ba. However,
40        with parentheses you could change this order: "a = (b + 3) * 5". In
41        R\bRP\bPN\bN, you would do "a = b, 3, +, 5, *" without the need for parentheses.
43 O\bOP\bPE\bER\bRA\bAT\bTO\bOR\bRS\bS
44        Boolean operators
45            L\bLT\bT,\b, L\bLE\bE,\b, G\bGT\bT,\b, G\bGE\bE,\b, E\bEQ\bQ,\b, N\bNE\bE
47            Pop two elements from the stack, compare them for the selected con-
48            dition and return 1 for true or 0 for false. Comparing an _\bu_\bn_\bk_\bn_\bo_\bw_\bn
49            or an _\bi_\bn_\bf_\bi_\bn_\bi_\bt_\be value will always result in 0 (false).
51            U\bUN\bN,\b, I\bIS\bSI\bIN\bNF\bF
53            Pop one element from the stack, compare this to _\bu_\bn_\bk_\bn_\bo_\bw_\bn respec-
54            tively to _\bp_\bo_\bs_\bi_\bt_\bi_\bv_\be _\bo_\br _\bn_\be_\bg_\ba_\bt_\bi_\bv_\be _\bi_\bn_\bf_\bi_\bn_\bi_\bt_\by. Returns 1 for true or 0
55            for false.
57            I\bIF\bF
59            Pops three elements from the stack.  If the element popped last is
60            0 (false), the value popped first is pushed back onto the stack,
61            otherwise the value popped second is pushed back. This does,
62            indeed, mean that any value other than 0 is considered to be true.
64            Example: "A,B,C,IF" should be read as "if (A) then (B) else (C)"
68        Comparing values
69            M\bMI\bIN\bN,\b, M\bMA\bAX\bX
71            Pops two elements from the stack and returns the smaller or larger,
72            respectively.  Note that _\bi_\bn_\bf_\bi_\bn_\bi_\bt_\be is larger than anything else.  If
73            one of the input numbers is _\bu_\bn_\bk_\bn_\bo_\bw_\bn then the result of the opera-
74            tion will be _\bu_\bn_\bk_\bn_\bo_\bw_\bn too.
76            L\bLI\bIM\bMI\bIT\bT
78            Pops two elements from the stack and uses them to define a range.
79            Then it pops another element and if it falls inside the range, it
80            is pushed back. If not, an _\bu_\bn_\bk_\bn_\bo_\bw_\bn is pushed.
82            The range defined includes the two boundaries (so: a number equal
83            to one of the boundaries will be pushed back). If any of the three
84            numbers involved is either _\bu_\bn_\bk_\bn_\bo_\bw_\bn or _\bi_\bn_\bf_\bi_\bn_\bi_\bt_\be this function will
85            always return an _\bu_\bn_\bk_\bn_\bo_\bw_\bn
87            Example: "CDEF:a=alpha,0,100,LIMIT" will return _\bu_\bn_\bk_\bn_\bo_\bw_\bn if alpha is
88            lower than 0 or if it is higher than 100.
92        Arithmetics
93            +\b+,\b, -\b-,\b, *\b*,\b, /\b/,\b, %\b%
95            Add, subtract, multiply, divide, modulo
97            A\bAD\bDD\bDN\bNA\bAN\bN
99            NAN-safe addition. If one parameter is NAN/UNKNOWN it'll be treated
100            as zero. If both parameters are NAN/UNKNOWN, NAN/UNKNOWN will be
101            returned.
103            S\bSI\bIN\bN,\b, C\bCO\bOS\bS,\b, L\bLO\bOG\bG,\b, E\bEX\bXP\bP,\b, S\bSQ\bQR\bRT\bT
105            Sine and cosine (input in radians), log and exp (natural loga-
106            rithm), square root.
108            A\bAT\bTA\bAN\bN
110            Arctangent (output in radians).
112            A\bAT\bTA\bAN\bN2\b2
114            Arctangent of y,x components (output in radians).  This pops one
115            element from the stack, the x (cosine) component, and then a sec-
116            ond, which is the y (sine) component.  It then pushes the arctan-
117            gent of their ratio, resolving the ambiguity between quadrants.
119            Example: "CDEF:angle=Y,X,ATAN2,RAD2DEG" will convert "X,Y" compo-
120            nents into an angle in degrees.
122            F\bFL\bLO\bOO\bOR\bR,\b, C\bCE\bEI\bIL\bL
124            Round down or up to the nearest integer.
126            D\bDE\bEG\bG2\b2R\bRA\bAD\bD,\b, R\bRA\bAD\bD2\b2D\bDE\bEG\bG
128            Convert angle in degrees to radians, or radians to degrees.
130            A\bAB\bBS\bS
132            Take the absolute value.
134        Set Operations
135            S\bSO\bOR\bRT\bT,\b, R\bRE\bEV\bV
137            Pop one element from the stack.  This is the _\bc_\bo_\bu_\bn_\bt of items to be
138            sorted (or reversed).  The top _\bc_\bo_\bu_\bn_\bt of the remaining elements are
139            then sorted (or reversed) in place on the stack.
141            Example: "CDEF:x=v1,v2,v3,v4,v5,v6,6,SORT,POP,5,REV,POP,+,+,+,4,/"
142            will compute the average of the values v1 to v6 after removing the
143            smallest and largest.
145            A\bAV\bVG\bG
147            Pop one element (_\bc_\bo_\bu_\bn_\bt) from the stack. Now pop _\bc_\bo_\bu_\bn_\bt elements and
148            build the average, ignoring all UNKNOWN values in the process.
150            Example: "CDEF:x=a,b,c,d,4,AVG"
152            T\bTR\bRE\bEN\bND\bD,\b, T\bTR\bRE\bEN\bND\bDN\bNA\bAN\bN
154            Create a "sliding window" average of another data series.
156            Usage: CDEF:smoothed=x,1800,TREND
158            This will create a half-hour (1800 second) sliding window average
159            of x.  The average is essentially computed as shown here:
161                             +---!---!---!---!---!---!---!---!--->
162                                                                 now
163                                   delay     t0
164                             <--------------->
165                                     delay       t1
166                                 <--------------->
167                                          delay      t2
168                                     <--------------->
170                 Value at sample (t0) will be the average between (t0-delay) and (t0)
171                 Value at sample (t1) will be the average between (t1-delay) and (t1)
172                 Value at sample (t2) will be the average between (t2-delay) and (t2)
174            TRENDNAN is - in contrast to TREND - NAN-safe. If you use TREND and
175            one source value is NAN the complete sliding window is affected.
176            The TRENDNAN operation ignores all NAN-values in a sliding window
177            and computes the average of the remaining values.
179            P\bPR\bRE\bED\bDI\bIC\bCT\bT,\b, P\bPR\bRE\bED\bDI\bIC\bCT\bTS\bSI\bIG\bGM\bMA\bA
181            Create a "sliding window" average/sigma of another data series,
182            that also shifts the data series by given amounts of of time as
183            well
185            Usage - explicit stating shifts: CDEF:predict=<shift n>,...,<shift
186            1>,n,<window>,x,PREDICT CDEF:sigma=<shift n>,...,<shift 1>,n,<win-
187            dow>,x,PREDICTSIGMA
189            Usage - shifts defined as a base shift and a number of time this is
190            applied CDEF:predict=<shift multiplier>,-n,<window>,x,PREDICT
191            CDEF:sigma=<shift multiplier>,-n,<window>,x,PREDICTSIGMA
193            Example: CDEF:predict=172800,86400,2,1800,x,PREDICT
195            This will create a half-hour (1800 second) sliding window aver-
196            age/sigma of x, that average is essentially computed as shown here:
198             +---!---!---!---!---!---!---!---!---!---!---!---!---!---!---!---!---!--->
199                                                                                 now
200                                                              shift 1        t0
201                                                     <----------------------->
202                                           window
203                                     <--------------->
204                                                   shift 2
205                             <----------------------------------------------->
206                   window
207             <--------------->
208                                                                  shift 1        t1
209                                                         <----------------------->
210                                               window
211                                         <--------------->
212                                                        shift 2
213                                 <----------------------------------------------->
214                       window
215                 <--------------->
217             Value at sample (t0) will be the average between (t0-shift1-window) and (t0-shift1)
218                                                  and between (t0-shift2-window) and (t0-shift2)
219             Value at sample (t1) will be the average between (t1-shift1-window) and (t1-shift1)
220                                                  and between (t1-shift2-window) and (t1-shift2)
222            The function is by design NAN-safe.  This also allows for extrapo-
223            lation into the future (say a few days) - you may need to define
224            the data series whit the optional start= parameter, so that the
225            source data series has enough data to provide prediction also at
226            the beginning of a graph...
228            Here an example, that will create a 10 day graph that also shows
229            the prediction 3 days into the future with its uncertainty value
230            (as defined by avg+-4*sigma) This also shows if the prediction is
231            exceeded at a certain point.
233            rrdtool graph image.png --imgformat=PNG \
234             --start=-7days --end=+3days --width=1000 --height=200
235            --alt-autoscale-max \
236             DEF:value=value.rrd:value:AVERAGE:start=-14days \
237             LINE1:value#ff0000:value \
238             CDEF:predict=86400,-7,1800,value,PREDICT \
239             CDEF:sigma=86400,-7,1800,value,PREDICTSIGMA \
240             CDEF:upper=predict,sigma,3,*,+ \
241             CDEF:lower=predict,sigma,3,*,- \
242             LINE1:predict#00ff00:prediction \
243             LINE1:upper#0000ff:upper\ certainty\ limit \
244             LINE1:lower#0000ff:lower\ certainty\ limit \
245             CDEF:exceeds=value,UN,0,value,lower,upper,LIMIT,UN,IF \
246             TICK:exceeds#aa000080:1
248            Note: Experience has shown that a factor between 3 and 5 to scale
249            sigma is a good discriminator to detect abnormal behaviour. This
250            obviously depends also on the type of data and how "noisy" the data
251            series is.
253            This prediction can only be used for short term extrapolations -
254            say a few days into the future-
256        Special values
257            U\bUN\bNK\bKN\bN
259            Pushes an unknown value on the stack
261            I\bIN\bNF\bF,\b, N\bNE\bEG\bGI\bIN\bNF\bF
263            Pushes a positive or negative infinite value on the stack. When
264            such a value is graphed, it appears at the top or bottom of the
265            graph, no matter what the actual value on the y-axis is.
267            P\bPR\bRE\bEV\bV
269            Pushes an _\bu_\bn_\bk_\bn_\bo_\bw_\bn value if this is the first value of a data set or
270            otherwise the result of this C\bCD\bDE\bEF\bF at the previous time step. This
271            allows you to do calculations across the data.  This function can-
272            not be used in V\bVD\bDE\bEF\bF instructions.
274            P\bPR\bRE\bEV\bV(\b(v\bvn\bna\bam\bme\be)\b)
276            Pushes an _\bu_\bn_\bk_\bn_\bo_\bw_\bn value if this is the first value of a data set or
277            otherwise the result of the vname variable at the previous time
278            step. This allows you to do calculations across the data. This
279            function cannot be used in V\bVD\bDE\bEF\bF instructions.
281            C\bCO\bOU\bUN\bNT\bT
283            Pushes the number 1 if this is the first value of the data set, the
284            number 2 if it is the second, and so on. This special value allows
285            you to make calculations based on the position of the value within
286            the data set. This function cannot be used in V\bVD\bDE\bEF\bF instructions.
288        Time
289            Time inside RRDtool is measured in seconds since the epoch. The
290            epoch is defined to be "Thu Jan 1 00:00:00 UTC 1970".
292            N\bNO\bOW\bW
294            Pushes the current time on the stack.
296            T\bTI\bIM\bME\bE
298            Pushes the time the currently processed value was taken at onto the
299            stack.
301            L\bLT\bTI\bIM\bME\bE
303            Takes the time as defined by T\bTI\bIM\bME\bE, applies the time zone offset
304            valid at that time including daylight saving time if your OS sup-
305            ports it, and pushes the result on the stack.  There is an elabo-
306            rate example in the examples section below on how to use this.
308        Processing the stack directly
309            D\bDU\bUP\bP,\b, P\bPO\bOP\bP,\b, E\bEX\bXC\bC
311            Duplicate the top element, remove the top element, exchange the two
312            top elements.
316 V\bVA\bAR\bRI\bIA\bAB\bBL\bLE\bES\bS
317        These operators work only on V\bVD\bDE\bEF\bF statements. Note that currently ONLY
318        these work for V\bVD\bDE\bEF\bF.
320        MAXIMUM, MINIMUM, AVERAGE
321            Return the corresponding value, MAXIMUM and MINIMUM also return the
322            first occurrence of that value in the time component.
324            Example: "VDEF:avg=mydata,AVERAGE"
326        STDEV
327            Returns the standard deviation of the values.
329            Example: "VDEF:stdev=mydata,STDEV"
331        LAST, FIRST
332            Return the last/first value including its time.  The time for FIRST
333            is actually the start of the corresponding interval, whereas LAST
334            returns the end of the corresponding interval.
336            Example: "VDEF:first=mydata,FIRST"
338        TOTAL
339            Returns the rate from each defined time slot multiplied with the
340            step size.  This can, for instance, return total bytes transfered
341            when you have logged bytes per second. The time component returns
342            the number of seconds.
344            Example: "VDEF:total=mydata,TOTAL"
346        PERCENT, PERCENTNAN
347            This should follow a D\bDE\bEF\bF or C\bCD\bDE\bEF\bF _\bv_\bn_\ba_\bm_\be. The _\bv_\bn_\ba_\bm_\be is popped,
348            another number is popped which is a certain percentage (0..100).
349            The data set is then sorted and the value returned is chosen such
350            that _\bp_\be_\br_\bc_\be_\bn_\bt_\ba_\bg_\be percent of the values is lower or equal than the
351            result.  For PERCENTNAN _\bU_\bn_\bk_\bn_\bo_\bw_\bn values are ignored, but for PERCENT
352            _\bU_\bn_\bk_\bn_\bo_\bw_\bn values are considered lower than any finite number for this
353            purpose so if this operator returns an _\bu_\bn_\bk_\bn_\bo_\bw_\bn you have quite a lot
354            of them in your data.  I\bIn\bnf\bfinite numbers are lesser, or more, than
355            the finite numbers and are always more than the _\bU_\bn_\bk_\bn_\bo_\bw_\bn numbers.
356            (NaN < -INF < finite values < INF)
358            Example: "VDEF:perc95=mydata,95,PERCENT"
359                     "VDEF:percnan95=mydata,95,PERCENTNAN"
361        LSLSLOPE, LSLINT, LSLCORREL
362            Return the parameters for a L\bLeast S\bSquares L\bLine _\b(_\by _\b= _\bm_\bx _\b+_\bb_\b) which
363            approximate the provided dataset.  LSLSLOPE is the slope _\b(_\bm_\b) of the
364            line related to the COUNT position of the data.  LSLINT is the
365            y-intercept _\b(_\bb_\b), which happens also to be the first data point on
366            the graph. LSLCORREL is the Correlation Coefficient (also know as
367            Pearson's Product Moment Correlation Coefficient).  It will range
368            from 0 to +/-1 and represents the quality of fit for the approxima-
369            tion.
371            Example: "VDEF:slope=mydata,LSLSLOPE"
373 S\bSE\bEE\bE A\bAL\bLS\bSO\bO
374        rrdgraph gives an overview of how r\brr\brd\bdt\bto\boo\bol\bl g\bgr\bra\bap\bph\bh works.  rrdgraph_data
375        describes D\bDE\bEF\bF,C\bCD\bDE\bEF\bF and V\bVD\bDE\bEF\bF in detail.  rrdgraph_rpn describes the R\bRP\bPN\bN
376        language used in the ?\b?D\bDE\bEF\bF statements.  rrdgraph_graph page describes
377        all of the graph and print functions.
379        Make sure to read rrdgraph_examples for tips&tricks.
381 A\bAU\bUT\bTH\bHO\bOR\bR
382        Program by Tobias Oetiker <tobi@oetiker.ch>
384        This manual page by Alex van den Bogaerdt <alex@vandenbogaerdt.nl> with
385        corrections and/or additions by several people
389 1.3.99909060808                   2009-02-21                   RRDGRAPH_RPN(1)