1RRDGRAPH_RPN(1)                     rrdtool                    RRDGRAPH_RPN(1)
2
3
4

NAME

6       rrdgraph_rpn - About RPN Math in rrdtool graph
7

SYNOPSIS

9       RPN expression:=vname|operator|value[,RPN expression]
10

DESCRIPTION

12       If you have ever used a traditional HP calculator you already know RPN
13       (Reverse Polish Notation).  The idea behind RPN is that you have a
14       stack and push your data onto this stack. Whenever you execute an
15       operation, it takes as many elements from the stack as needed. Pushing
16       is done implicitly, so whenever you specify a number or a variable, it
17       gets pushed onto the stack automatically.
18
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 vname.  For CDEF instructions, the stack is
22       processed for each data point on the graph. VDEF instructions work on
23       an entire data set in one run. Note, that currently VDEF instructions
24       only support a limited list of functions.
25
26       Example: "VDEF:maximum=mydata,MAXIMUM"
27
28       This will set variable "maximum" which you now can use in the rest of
29       your RRD script.
30
31       Example: "CDEF:mydatabits=mydata,8,*"
32
33       This means:  push variable mydata, push the number 8, execute the
34       operator *. The operator needs two elements and uses those to return
35       one value.  This value is then stored in mydatabits.  As you may have
36       guessed, this instruction means nothing more than mydatabits = mydata *
37       8.  The real power of RPN 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 b to get a. However,
40       with parentheses you could change this order: "a = (b + 3) * 5". In
41       RPN, you would do "a = b, 3, +, 5, *" without the need for parentheses.
42

OPERATORS

44       Boolean operators
45           LT, LE, GT, GE, EQ, NE
46
47           Pop two elements from the stack, compare them for the selected
48           condition and return 1 for true or 0 for false. Comparing an
49           unknown or an infinite value will always result in 0 (false).
50
51           UN, ISINF
52
53           Pop one element from the stack, compare this to unknown
54           respectively to positive or negative infinity. Returns 1 for true
55           or 0 for false.
56
57           IF
58
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.
63
64           Example: "A,B,C,IF" should be read as "if (A) then (B) else (C)"
65
66
67
68       Comparing values
69           MIN, MAX
70
71           Pops two elements from the stack and returns the smaller or larger,
72           respectively.  Note that infinite is larger than anything else.  If
73           one of the input numbers is unknown then the result of the
74           operation will be unknown too.
75
76           LIMIT
77
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 unknown is pushed.
81
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 unknown or infinite this function will
85           always return an unknown
86
87           Example: "CDEF:a=alpha,0,100,LIMIT" will return unknown if alpha is
88           lower than 0 or if it is higher than 100.
89
90
91
92       Arithmetics
93           +, -, *, /, %
94
95           Add, subtract, multiply, divide, modulo
96
97           ADDNAN
98
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.
102
103           SIN, COS, LOG, EXP, SQRT
104
105           Sine and cosine (input in radians), log and exp (natural
106           logarithm), square root.
107
108           ATAN
109
110           Arctangent (output in radians).
111
112           ATAN2
113
114           Arctangent of y,x components (output in radians).  This pops one
115           element from the stack, the x (cosine) component, and then a
116           second, which is the y (sine) component.  It then pushes the
117           arctangent of their ratio, resolving the ambiguity between
118           quadrants.
119
120           Example: "CDEF:angle=Y,X,ATAN2,RAD2DEG" will convert "X,Y"
121           components into an angle in degrees.
122
123           FLOOR, CEIL
124
125           Round down or up to the nearest integer.
126
127           DEG2RAD, RAD2DEG
128
129           Convert angle in degrees to radians, or radians to degrees.
130
131           ABS
132
133           Take the absolute value.
134
135       Set Operations
136           SORT, REV
137
138           Pop one element from the stack.  This is the count of items to be
139           sorted (or reversed).  The top count of the remaining elements are
140           then sorted (or reversed) in place on the stack.
141
142           Example: "CDEF:x=v1,v2,v3,v4,v5,v6,6,SORT,POP,5,REV,POP,+,+,+,4,/"
143           will compute the average of the values v1 to v6 after removing the
144           smallest and largest.
145
146           AVG
147
148           Pop one element (count) from the stack. Now pop count elements and
149           build the average, ignoring all UNKNOWN values in the process.
150
151           Example: "CDEF:x=a,b,c,d,4,AVG"
152
153           TREND, TRENDNAN
154
155           Create a "sliding window" average of another data series.
156
157           Usage: CDEF:smoothed=x,1800,TREND
158
159           This will create a half-hour (1800 second) sliding window average
160           of x.  The average is essentially computed as shown here:
161
162                            +---!---!---!---!---!---!---!---!--->
163                                                                now
164                                  delay     t0
165                            <--------------->
166                                    delay       t1
167                                <--------------->
168                                         delay      t2
169                                    <--------------->
170
171
172                Value at sample (t0) will be the average between (t0-delay) and (t0)
173                Value at sample (t1) will be the average between (t1-delay) and (t1)
174                Value at sample (t2) will be the average between (t2-delay) and (t2)
175
176           TRENDNAN is - in contrast to TREND - NAN-safe. If you use TREND and
177           one source value is NAN the complete sliding window is affected.
178           The TRENDNAN operation ignores all NAN-values in a sliding window
179           and computes the average of the remaining values.
180
181       Special values
182           UNKN
183
184           Pushes an unknown value on the stack
185
186           INF, NEGINF
187
188           Pushes a positive or negative infinite value on the stack. When
189           such a value is graphed, it appears at the top or bottom of the
190           graph, no matter what the actual value on the y-axis is.
191
192           PREV
193
194           Pushes an unknown value if this is the first value of a data set or
195           otherwise the result of this CDEF at the previous time step. This
196           allows you to do calculations across the data.  This function
197           cannot be used in VDEF instructions.
198
199           PREV(vname)
200
201           Pushes an unknown value if this is the first value of a data set or
202           otherwise the result of the vname variable at the previous time
203           step. This allows you to do calculations across the data. This
204           function cannot be used in VDEF instructions.
205
206           COUNT
207
208           Pushes the number 1 if this is the first value of the data set, the
209           number 2 if it is the second, and so on. This special value allows
210           you to make calculations based on the position of the value within
211           the data set. This function cannot be used in VDEF instructions.
212
213       Time
214           Time inside RRDtool is measured in seconds since the epoch. The
215           epoch is defined to be "Thu Jan  1 00:00:00 UTC 1970".
216
217           NOW
218
219           Pushes the current time on the stack.
220
221           TIME
222
223           Pushes the time the currently processed value was taken at onto the
224           stack.
225
226           LTIME
227
228           Takes the time as defined by TIME, applies the time zone offset
229           valid at that time including daylight saving time if your OS
230           supports it, and pushes the result on the stack.  There is an
231           elaborate example in the examples section below on how to use this.
232
233       Processing the stack directly
234           DUP, POP, EXC
235
236           Duplicate the top element, remove the top element, exchange the two
237           top elements.
238
239
240

VARIABLES

242       These operators work only on VDEF statements. Note that currently ONLY
243       these work for VDEF.
244
245       MAXIMUM, MINIMUM, AVERAGE
246           Return the corresponding value, MAXIMUM and MINIMUM also return the
247           first occurrence of that value in the time component.
248
249           Example: "VDEF:avg=mydata,AVERAGE"
250
251       STDEV
252           Returns the standard deviation of the values.
253
254           Example: "VDEF:stdev=mydata,STDEV"
255
256       LAST, FIRST
257           Return the last/first value including its time.  The time for FIRST
258           is actually the start of the corresponding interval, whereas LAST
259           returns the end of the corresponding interval.
260
261           Example: "VDEF:first=mydata,FIRST"
262
263       TOTAL
264           Returns the rate from each defined time slot multiplied with the
265           step size.  This can, for instance, return total bytes transfered
266           when you have logged bytes per second. The time component returns
267           the number of seconds.
268
269           Example: "VDEF:total=mydata,TOTAL"
270
271       PERCENT
272           This should follow a DEF or CDEF vname. The vname is popped,
273           another number is popped which is a certain percentage (0..100).
274           The data set is then sorted and the value returned is chosen such
275           that percentage percent of the values is lower or equal than the
276           result.  Unknown values are considered lower than any finite number
277           for this purpose so if this operator returns an unknown you have
278           quite a lot of them in your data.  Infinite numbers are lesser, or
279           more, than the finite numbers and are always more than the Unknown
280           numbers.  (NaN < -INF < finite values < INF)
281
282           Example: "VDEF:perc95=mydata,95,PERCENT"
283
284       LSLSLOPE, LSLINT, LSLCORREL
285           Return the parameters for a Least Squares Line (y = mx +b) which
286           approximate the provided dataset.  LSLSLOPE is the slope (m) of the
287           line related to the COUNT position of the data.  LSLINT is the
288           y-intercept (b), which happens also to be the first data point on
289           the graph. LSLCORREL is the Correlation Coefficient (also know as
290           Pearson's Product Moment Correlation Coefficient).  It will range
291           from 0 to +/-1 and represents the quality of fit for the
292           approximation.
293
294           Example: "VDEF:slope=mydata,LSLSLOPE"
295

SEE ALSO

297       rrdgraph gives an overview of how rrdtool graph works.  rrdgraph_data
298       describes DEF,CDEF and VDEF in detail.  rrdgraph_rpn describes the RPN
299       language used in the ?DEF statements.  rrdgraph_graph page describes
300       all of the graph and print functions.
301
302       Make sure to read rrdgraph_examples for tips&tricks.
303

AUTHOR

305       Program by Tobias Oetiker <tobi@oetiker.ch>
306
307       This manual page by Alex van den Bogaerdt <alex@vandenbogaerdt.nl> with
308       corrections and/or additions by several people
309
310
311
3121.3.8                             2009-02-21                   RRDGRAPH_RPN(1)
Impressum