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       The idea behind RPN is that you have a stack and push your data onto
14       this stack. Whenever you execute an operation, it takes as many ele‐
15       ments from the stack as needed. Pushing is done implicitly, so whenever
16       you specify a number or a variable, it gets pushed onto the stack auto‐
17       matically.
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 pro‐
22       cessed for each data point on the graph. VDEF instructions work on an
23       entire data set in one run. Note, that currently VDEF instructions only
24       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 oper‐
34       ator *. The operator needs two elements and uses those to return one
35       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 con‐
48           dition and return 1 for true or 0 for false. Comparing an unknown
49           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 respec‐
54           tively to positive or negative infinity. Returns 1 for true or 0
55           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       Comparing values
67           MIN, MAX
68
69           Pops two elements from the stack and returns the smaller or larger,
70           respectively.  Note that infinite is larger than anything else.  If
71           one of the input numbers is unknown then the result of the opera‐
72           tion will be unknown too.
73
74           LIMIT
75
76           Pops two elements from the stack and uses them to define a range.
77           Then it pops another element and if it falls inside the range, it
78           is pushed back. If not, an unknown is pushed.
79
80           The range defined includes the two boundaries (so: a number equal
81           to one of the boundaries will be pushed back). If any of the three
82           numbers involved is either unknown or infinite this function will
83           always return an unknown
84
85           Example: "CDEF:a=alpha,0,100,LIMIT" will return unknown if alpha is
86           lower than 0 or if it is higher than 100.
87
88       Arithmetics
89           +, -, *, /, %
90
91           Add, subtract, multiply, divide, modulo
92
93           SIN, COS, LOG, EXP, SQRT
94
95           Sine and cosine (input in radians), log and exp (natural loga‐
96           rithm), square root.
97
98           ATAN
99
100           Arctangent (output in radians).
101
102           ATAN2
103
104           Arctangent of y,x components (output in radians).  This pops one
105           element from the stack, the x (cosine) component, and then a sec‐
106           ond, which is the y (sine) component.  It then pushes the arctan‐
107           gent of their ratio, resolving the ambiguity between quadrants.
108
109           Example: "CDEF:angle=Y,X,ATAN2,RAD2DEG" will convert "X,Y" compo‐
110           nents into an angle in degrees.
111
112           FLOOR, CEIL
113
114           Round down or up to the nearest integer.
115
116           DEG2RAD, RAD2DEG
117
118           Convert angle in degrees to radians, or radians to degrees.
119
120           ABS
121
122           Take the absolute value.
123
124       Set Operations
125           SORT, REV
126
127           Pop one element from the stack.  This is the count of items to be
128           sorted (or reversed).  The top count of the remaining elements are
129           then sorted (or reversed) in place on the stack.
130
131           Example: "CDEF:x=v1,v2,v3,v4,v5,v6,6,SORT,POP,5,REV,POP,+,+,+,4,/"
132           will compute the average of the values v1 to v6 after removing the
133           smallest and largest.
134
135           AVG
136
137           Pop one element (count) from the stack. Now pop count elements and
138           build the average, ignoring all UNKNOWN values in the process.
139
140           Example: "CDEF:x=a,b,c,d,4,AVG"
141
142           TREND
143
144           Create a "sliding window" average of another data series.
145
146           Usage: CDEF:smoothed=x,1800,TREND
147
148           This will create a half-hour (1800 second) sliding window average
149           of x.  The average is essentially computed as shown here:
150
151                            +---!---!---!---!---!---!---!---!--->
152                                                                now
153                                  delay     t0
154                            <--------------->
155                                    delay       t1
156                                <--------------->
157                                         delay      t2
158                                    <--------------->
159
160                Value at sample (t0) will be the average between (t0-delay) and (t0)
161                Value at sample (t1) will be the average between (t1-delay) and (t1)
162                Value at sample (t2) will be the average between (t2-delay) and (t2)
163
164       Special values
165           UNKN
166
167           Pushes an unknown value on the stack
168
169           INF, NEGINF
170
171           Pushes a positive or negative infinite value on the stack. When
172           such a value is graphed, it appears at the top or bottom of the
173           graph, no matter what the actual value on the y-axis is.
174
175           PREV
176
177           Pushes an unknown value if this is the first value of a data set or
178           otherwise the result of this CDEF at the previous time step. This
179           allows you to do calculations across the data.  This function can‐
180           not be used in VDEF instructions.
181
182           PREV(vname)
183
184           Pushes an unknown value if this is the first value of a data set or
185           otherwise the result of the vname variable at the previous time
186           step. This allows you to do calculations across the data. This
187           function cannot be used in VDEF instructions.
188
189           COUNT
190
191           Pushes the number 1 if this is the first value of the data set, the
192           number 2 if it is the second, and so on. This special value allows
193           you to make calculations based on the position of the value within
194           the data set. This function cannot be used in VDEF instructions.
195
196       Time
197           Time inside RRDtool is measured in seconds since the epoch. The
198           epoch is defined to be "Thu Jan 1 00:00:00 UTC 1970".
199
200           NOW
201
202           Pushes the current time on the stack.
203
204           TIME
205
206           Pushes the time the currently processed value was taken at onto the
207           stack.
208
209           LTIME
210
211           Takes the time as defined by TIME, applies the time zone offset
212           valid at that time including daylight saving time if your OS sup‐
213           ports it, and pushes the result on the stack.  There is an elabo‐
214           rate example in the examples section below on how to use this.
215
216       Processing the stack directly
217           DUP, POP, EXC
218
219           Duplicate the top element, remove the top element, exchange the two
220           top elements.
221

VARIABLES

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

SEE ALSO

273       rrdgraph gives an overview of how rrdtool graph works.  rrdgraph_data
274       describes DEF,CDEF and VDEF in detail.  rrdgraph_rpn describes the RPN
275       language used in the ?DEF statements.  rrdgraph_graph page describes
276       all of the graph and print functions.
277
278       Make sure to read rrdgraph_examples for tips&tricks.
279

AUTHOR

281       Program by Tobias Oetiker <tobi@oetiker.ch>
282
283       This manual page by Alex van den Bogaerdt <alex@ergens.op.het.net>
284
285
286
2871.2.27                            2008-02-17                   RRDGRAPH_RPN(1)
Impressum