1 RRDGRAPH_RPN(1) rrdtool RRDGRAPH_RPN(1)
6 rrdgraph_rpn - About RPN Math in rrdtool graph
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]
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.
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
24 only 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,*"
34 operator _\b*. The operator needs two elements and uses those to return
35 one 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*
38 which order to process the input. For expressions like "a = b + 3 * 5"
40 with parentheses you could change this order: "a = (b + 3) * 5". In
44 Boolean operators
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 _\bu_\bn_\bk_\bn_\bo_\bw_\bn or an _\bi_\bn_\bf_\bi_\bn_\bi_\bt_\be value will always result in 0 (false).
54 respectively 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
55 or 0 for false.
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
71 Pops two elements from the stack and returns the smaller or larger,
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
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
88 lower than 0 or if it is higher than 100.
92 Arithmetics
95 Add, subtract, multiply, divide, modulo
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.
105 Sine and cosine (input in radians), log and exp (natural
106 logarithm), square root.
110 Arctangent (output in radians).
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.
120 Example: "CDEF:angle=Y,X,ATAN2,RAD2DEG" will convert "X,Y"
121 components into an angle in degrees.
125 Round down or up to the nearest integer.
129 Convert angle in degrees to radians, or radians to degrees.
133 Take the absolute value.
135 Set Operations
140 then sorted (or reversed) in place on the stack.
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.
148 Pop one element (_\bc_\bo_\bu_\bn_\bt) from the stack. Now pop _\bc_\bo_\bu_\bn_\bt elements and
149 build the average, ignoring all UNKNOWN values in the process.
151 Example: "CDEF:x=a,b,c,d,4,AVG"
155 Create a "sliding window" average of another data series.
157 Usage: CDEF:smoothed=x,1800,TREND
159 This will create a half-hour (1800 second) sliding window average
160 of x. The average is essentially computed as shown here:
162 +---!---!---!---!---!---!---!---!--->
163 now
164 delay t0
165 <--------------->
166 delay t1
167 <--------------->
168 delay t2
169 <--------------->
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)
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.
183 Create a "sliding window" average/sigma of another data series,
184 that also shifts the data series by given amounts of of time as
185 well
187 Usage - explicit stating shifts: CDEF:predict=<shift n>,...,<shift
188 1>,n,<window>,x,PREDICT CDEF:sigma=<shift n>,...,<shift
189 1>,n,<window>,x,PREDICTSIGMA
191 Usage - shifts defined as a base shift and a number of time this is
192 applied CDEF:predict=<shift multiplier>,-n,<window>,x,PREDICT
193 CDEF:sigma=<shift multiplier>,-n,<window>,x,PREDICTSIGMA
195 Example: CDEF:predict=172800,86400,2,1800,x,PREDICT
197 This will create a half-hour (1800 second) sliding window
198 average/sigma of x, that average is essentially computed as shown
199 here:
201 +---!---!---!---!---!---!---!---!---!---!---!---!---!---!---!---!---!--->
202 now
203 shift 1 t0
204 <----------------------->
205 window
206 <--------------->
207 shift 2
208 <----------------------------------------------->
209 window
210 <--------------->
211 shift 1 t1
212 <----------------------->
213 window
214 <--------------->
215 shift 2
216 <----------------------------------------------->
217 window
218 <--------------->
220 Value at sample (t0) will be the average between (t0-shift1-window) and (t0-shift1)
221 and between (t0-shift2-window) and (t0-shift2)
222 Value at sample (t1) will be the average between (t1-shift1-window) and (t1-shift1)
223 and between (t1-shift2-window) and (t1-shift2)
225 The function is by design NAN-safe. This also allows for
226 extrapolation into the future (say a few days) - you may need to
227 define the data series whit the optional start= parameter, so that
228 the source data series has enough data to provide prediction also
229 at the beginning of a graph...
231 Here an example, that will create a 10 day graph that also shows
232 the prediction 3 days into the future with its uncertainty value
233 (as defined by avg+-4*sigma) This also shows if the prediction is
234 exceeded at a certain point.
236 rrdtool graph image.png --imgformat=PNG \
237 --start=-7days --end=+3days --width=1000 --height=200
238 --alt-autoscale-max \
239 DEF:value=value.rrd:value:AVERAGE:start=-14days \
240 LINE1:value#ff0000:value \
241 CDEF:predict=86400,-7,1800,value,PREDICT \
242 CDEF:sigma=86400,-7,1800,value,PREDICTSIGMA \
243 CDEF:upper=predict,sigma,3,*,+ \
244 CDEF:lower=predict,sigma,3,*,- \
245 LINE1:predict#00ff00:prediction \
246 LINE1:upper#0000ff:upper\ certainty\ limit \
247 LINE1:lower#0000ff:lower\ certainty\ limit \
248 CDEF:exceeds=value,UN,0,value,lower,upper,LIMIT,UN,IF \
249 TICK:exceeds#aa000080:1
251 Note: Experience has shown that a factor between 3 and 5 to scale
252 sigma is a good discriminator to detect abnormal behavior. This
253 obviously depends also on the type of data and how "noisy" the data
254 series is.
256 This prediction can only be used for short term extrapolations -
257 say a few days into the future-
259 Special values
262 Pushes an unknown value on the stack
266 Pushes a positive or negative infinite value on the stack. When
267 such a value is graphed, it appears at the top or bottom of the
268 graph, no matter what the actual value on the y-axis is.
274 allows you to do calculations across the data. This function
280 otherwise the result of the vname variable at the previous time
281 step. This allows you to do calculations across the data. This
286 Pushes the number 1 if this is the first value of the data set, the
287 number 2 if it is the second, and so on. This special value allows
288 you to make calculations based on the position of the value within
291 Time
292 Time inside RRDtool is measured in seconds since the epoch. The
293 epoch is defined to be "Thu Jan 1 00:00:00 UTC 1970".
297 Pushes the current time on the stack.
301 Pushes the time the currently processed value was taken at onto the
302 stack.
307 valid at that time including daylight saving time if your OS
308 supports it, and pushes the result on the stack. There is an
309 elaborate example in the examples section below on how to use this.
311 Processing the stack directly
314 Duplicate the top element, remove the top element, exchange the two
315 top elements.
323 MAXIMUM, MINIMUM, AVERAGE
324 Return the corresponding value, MAXIMUM and MINIMUM also return the
325 first occurrence of that value in the time component.
327 Example: "VDEF:avg=mydata,AVERAGE"
329 STDEV
330 Returns the standard deviation of the values.
332 Example: "VDEF:stdev=mydata,STDEV"
334 LAST, FIRST
335 Return the last/first value including its time. The time for FIRST
336 is actually the start of the corresponding interval, whereas LAST
337 returns the end of the corresponding interval.
339 Example: "VDEF:first=mydata,FIRST"
341 TOTAL
342 Returns the rate from each defined time slot multiplied with the
343 step size. This can, for instance, return total bytes transferred
344 when you have logged bytes per second. The time component returns
345 the number of seconds.
347 Example: "VDEF:total=mydata,TOTAL"
349 PERCENT, PERCENTNAN
350 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,
351 another number is popped which is a certain percentage (0..100).
352 The data set is then sorted and the value returned is chosen such
359 (NaN < -INF < finite values < INF)
361 Example: "VDEF:perc95=mydata,95,PERCENT"
362 "VDEF:percnan95=mydata,95,PERCENTNAN"
364 LSLSLOPE, LSLINT, LSLCORREL
365 Return the parameters for a L\bLeast S\bSquares L\bLine _\b(_\by _\b= _\bm_\bx _\b+_\bb_\b) which
367 line related to the COUNT position of the data. LSLINT is the
369 the graph. LSLCORREL is the Correlation Coefficient (also know as
370 Pearson's Product Moment Correlation Coefficient). It will range
371 from 0 to +/-1 and represents the quality of fit for the
372 approximation.
374 Example: "VDEF:slope=mydata,LSLSLOPE"
377 rrdgraph gives an overview of how r\brr\brd\bdt\bto\boo\bol\bl g\bgr\bra\bap\bph\bh works. rrdgraph_data
378 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
380 all of the graph and print functions.
382 Make sure to read rrdgraph_examples for tips&tricks.
385 Program by Tobias Oetiker <tobi@oetiker.ch>
387 This manual page by Alex van den Bogaerdt <alex@vandenbogaerdt.nl> with
388 corrections and/or additions by several people
392 1.4.2 2009-10-14 RRDGRAPH_RPN(1)