Support for COMPUTE data sources (CDEF data sources). Removes the RPN
[rrdtool.git] / doc / rrdcreate.pod
1 =head1 NAME
2
3 rrdtool create - Set up a new Round Robin Database
4
5 =for html <div align="right"><a href="rrdcreate.pdf">PDF</a> version.</div>
6
7 =head1 SYNOPSIS
8
9 B<rrdtool> B<create> I<filename> 
10 S<[B<--start>|B<-b> I<start time>]> 
11 S<[B<--step>|B<-s> I<step>]> 
12 S<[B<DS:>I<ds-name>B<:>I<DST>B<:>I<dst arguments>]>
13 I<heartbeat>B<:>I<min>B<:>I<max>]>
14 S<[B<RRA:>I<CF>B<:>I<cf arguments>]>
15
16 =head1 DESCRIPTION
17
18 The create function of the RRDtool lets you set up new
19 Round Robin Database (B<RRD>) files. 
20 The file is created at its final, full size and filled
21 with I<*UNKNOWN*> data.
22
23 =over 8
24
25 =item I<filename>
26
27 The name of the B<RRD> you want to create. B<RRD> files should end
28 with the extension F<.rrd>. However, B<rrdtool> will accept any
29 filename.
30
31 =item B<--start>|B<-b> I<start time> (default: now - 10s)
32
33 Specifies the time in seconds since 1970-01-01 UTC when the first
34 value should be added to the B<RRD>. B<rrdtool> will not accept
35 any data timed before or at the time specified.
36
37 See also AT-STYLE TIME SPECIFICATION section in the
38 I<rrdfetch> documentation for more ways to specify time.
39
40 =item B<--step>|B<-s> I<step> (default: 300 seconds)
41
42 Specifies the base interval in seconds with which data will be fed
43 into the B<RRD>.
44
45 =item B<DS:>I<ds-name>B<:>I<DST>B<:>I<dst arguments>
46
47 A single B<RRD> can accept input from several data sources (B<DS>).
48 (e.g. Incoming and Outgoing traffic on a specific communication
49 line). With the B<DS> configuration option you must define some basic
50 properties of each data source you want to use to feed the B<RRD>.
51
52 I<ds-name> is the name you will use to reference this particular data
53 source from an B<RRD>. A I<ds-name> must be 1 to 19 characters long in
54 the characters [a-zA-Z0-9_].
55
56 I<DST> defines the Data Source Type. The remaining arguments of a
57 data source entry depend upon the data source type. For GAUGE, COUNTER,
58 DERIVE, and ABSOLUTE the format for a data source entry is:
59
60 B<DS:>I<ds-name>B<:>I<GAUGE | COUNTER | DERIVE | ABSOLUTE>B<:>I<heartbeat>B<:>I<min>B<:>I<max>
61
62 For COMPUTE data sources, the format is:
63
64 B<DS:>I<ds-name>B<:>I<COMPUTE>B<:>I<rpn-expression>
65
66 To decide on a data source type, review the definitions that follow. 
67 Consult the section on "HOW TO MEASURE" for further insight.
68
69 =over 4
70
71 =item B<GAUGE> 
72
73 is for things like temperatures or number of people in a
74 room or value of a RedHat share.
75
76 =item B<COUNTER>
77
78 is for continuous incrementing counters like the
79 InOctets counter in a router. The B<COUNTER> data source assumes that
80 the counter never decreases, except when a counter overflows.  The update
81 function takes the overflow into account.  The counter is stored as a
82 per-second rate. When the counter overflows, RRDtool checks if the overflow happened at
83 the 32bit or 64bit border and acts accordingly by adding an appropriate value to the result.
84
85 =item B<DERIVE>
86
87 will store the derivative of the line going from the last to the
88 current value of the data source. This can be useful for gauges, for
89 example, to measure the rate of people entering or leaving a
90 room. Internally, derive works exaclty like COUNTER but without
91 overflow checks. So if your counter does not reset at 32 or 64 bit you
92 might want to use DERIVE and combine it with a MIN value of 0.
93
94 =over
95
96 =item NOTE on COUNTER vs DERIVE
97
98 by Don Baarda E<lt>don.baarda@baesystems.comE<gt>
99
100 If you cannot tolerate ever mistaking the occasional counter reset for a
101 legitimate counter wrap, and would prefer "Unknowns" for all legitimate
102 counter wraps and resets, always use DERIVE with min=0. Otherwise, using
103 COUNTER with a suitable max will return correct values for all legitimate
104 counter wraps, mark some counter resets as "Unknown", but can mistake some
105 counter resets for a legitimate counter wrap.
106
107 For a 5 minute step and 32-bit counter, the probability of mistaking a
108 counter reset for a legitimate wrap is arguably about 0.8% per 1Mbps of
109 maximum bandwidth. Note that this equates to 80% for 100Mbps interfaces, so
110 for high bandwidth interfaces and a 32bit counter, DERIVE with min=0 is
111 probably preferable. If you are using a 64bit counter, just about any max
112 setting will eliminate the possibility of mistaking a reset for a counter
113 wrap.
114
115 =back
116
117 =item B<ABSOLUTE> 
118
119 is for counters which get reset upon reading. This is used for fast counters
120 which tend to overflow. So instead of reading them normally you reset them
121 after every read to make sure you have a maximal time available before the
122 next overflow. Another usage is for things you count like number of messages
123 since the last update.
124
125 =item B<COMPUTE>
126
127 is for storing the result of a formula applied to other data sources in
128 the B<RRD>. This data source is not supplied a value on update, but rather
129 its Primary Data Points (PDPs) are computed from the PDPs of the data sources
130 according to the rpn-expression that defines the formula. Consolidation 
131 functions are then applied normally to the PDPs of the COMPUTE data source
132 (that is the rpn-expression is only applied to generate PDPs). In database
133 software, these are referred to as "virtual" or "computed" columns.
134
135 =back
136
137 I<heartbeat> defines the maximum number of seconds that may pass
138 between two updates of this data source before the value of the 
139 data source is assumed to be I<*UNKNOWN*>.
140
141 I<min> and I<max> are optional entries defining the expected range of
142 the data supplied by this data source. If I<min> and/or I<max> are
143 defined, any value outside the defined range will be regarded as
144 I<*UNKNOWN*>. If you do not know or care about min and max, set them
145 to U for unknown. Note that min and max always refer to the processed values
146 of the DS. For a traffic-B<COUNTER> type DS this would be the max and min
147 data-rate expected from the device.
148
149 I<If information on minimal/maximal expected values is available,
150 always set the min and/or max properties. This will help RRDtool in
151 doing a simple sanity check on the data supplied when running update.>
152
153 I<rpn-expression> defines the formula used to compute the PDPs of a COMPUTE
154 data source from other data sources in the same <RRD>. It is similar to defining
155 a B<CDEF> argument for the graph command. Please refer to that manual page
156 for a list and description of RPN operations supported. For
157 COMPUTE data sources, the following RPN operations are not supported: PREV,
158 TIME, and LTIME. In addition, in defining the RPN expression, the COMPUTE
159 data source may only refer to the names of data source listed previously
160 in the create command. This is similar to the restriction that B<CDEF>s must
161 refer only to B<DEF>s and B<CDEF>s previously defined in the same graph command.
162
163 =item B<RRA:>I<CF>B<:>I<cf arguments>
164   
165 The purpose of an B<RRD> is to store data in the round robin archives
166 (B<RRA>). An archive consists of a number of data values or statistics for 
167 each of the defined data-sources (B<DS>) and is defined with an B<RRA> line.
168
169 When data is entered into an B<RRD>, it is first fit into time slots of
170 the length defined with the B<-s> option becoming a I<primary data point>.
171
172 The data is also processed with the consolidation function (I<CF>)
173 of the archive. There are several consolidation functions that consolidate
174 primary data points via an aggregate function: B<AVERAGE>, B<MIN>, B<MAX>, B<LAST>.
175 The format of B<RRA> line for these consolidation functions is:
176
177 B<RRA:>I<AVERAGE | MIN | MAX | LAST>B<:>I<xff>B<:>I<steps>B<:>I<rows>
178
179 I<xff> The xfiles factor defines what part of a consolidation interval may
180 be made up from I<*UNKNOWN*> data while the consolidated value is still
181 regarded as known.
182
183 I<steps> defines how many of these I<primary data points> are used to build
184 a I<consolidated data point> which then goes into the archive.
185
186 I<rows> defines how many generations of data values are kept in an B<RRA>.
187
188 =back
189
190 =head1 Aberrant Behaviour detection with Holt-Winters forecasting
191
192 by Jake Brutlag E<lt>jakeb@corp.webtv.netE<gt>
193
194 In addition to the aggregate functions, there are a set of specialized
195 functions that enable B<RRDtool> to provide data smoothing (via the
196 Holt-Winters forecasting algorithm), confidence bands, and the flagging
197 aberrant behavior in the data source time series:
198
199 =over 4
200
201 =item B<RRA:>I<HWPREDICT>B<:>I<rows>B<:>I<alpha>B<:>I<beta>B<:>I<seasonal period>B<:>I<rra num>
202
203 =item B<RRA:>I<SEASONAL>B<:>I<seasonal period>B<:>I<gamma>B<:>I<rra num>
204
205 =item B<RRA:>I<DEVSEASONAL>B<:>I<seasonal period>B<:>I<gamma>B<:>I<rra num>
206
207 =item B<RRA:>I<DEVPREDICT>B<:>I<rows>B<:>I<rra num>
208
209 =item B<RRA:>I<FAILURES>B<:>I<rows>B<:>I<threshold>B<:>I<window length>B<:>I<rra num>
210
211 =back
212
213 These B<RRAs> differ from the true consolidation functions in several ways.
214 First, each of the B<RRA>s is updated once for every primary data point.
215 Second, these B<RRAs> are interdependent. To generate real-time confidence
216 bounds, then a matched set of HWPREDICT, SEASONAL, DEVSEASONAL, and
217 DEVPREDICT must exist. Generating smoothed values of the primary data points
218 requires both a HWPREDICT B<RRA> and SEASONAL B<RRA>. Aberrant behavior
219 detection requires FAILURES, HWPREDICT, DEVSEASONAL, and SEASONAL.
220
221 The actual predicted, or smoothed, values are stored in the HWPREDICT
222 B<RRA>. The predicted deviations are store in DEVPREDICT (think a standard
223 deviation which can be scaled to yield a confidence band). The FAILURES
224 B<RRA> stores binary indicators. A 1 marks the indexed observation a
225 failure; that is, the number of confidence bounds violations in the
226 preceding window of observations met or exceeded a specified threshold. An
227 example of using these B<RRAs> to graph confidence bounds and failures
228 appears in L<rrdgraph>.
229
230 The SEASONAL and DEVSEASONAL B<RRAs> store the seasonal coefficients for the
231 Holt-Winters Forecasting algorithm and the seasonal deviations respectively.
232 There is one entry per observation time point in the seasonal cycle. For
233 example, if primary data points are generated every five minutes, and the
234 seasonal cycle is 1 day, both SEASONAL and DEVSEASONAL with have 288 rows.
235
236 In order to simplify the creation for the novice user, in addition to
237 supporting explicit creation the HWPREDICT, SEASONAL, DEVPREDICT,
238 DEVSEASONAL, and FAILURES B<RRAs>, the B<rrdtool> create command supports
239 implicit creation of the other four when HWPREDICT is specified alone and
240 the final argument I<rra num> is omitted.
241
242 I<rows> specifies the length of the B<RRA> prior to wrap around. Remember
243 that there is a one-to-one correspondence between primary data points and
244 entries in these RRAs. For the HWPREDICT CF, I<rows> should be larger than
245 the I<seasonal period>. If the DEVPREDICT B<RRA> is implicity created, the
246 default number of rows is the same as the HWPREDICT I<rows> argument. If the
247 FAILURES B<RRA> is implicitly created, I<rows> will be set to the I<seasonal
248 period> argument of the HWPREDICT B<RRA>. Of course, the B<rrdtool>
249 I<resize> command is available if these defaults are not sufficient and the
250 create wishes to avoid explicit creations of the other specialized function
251 B<RRAs>.
252
253 I<seasonal period> specifies the number of primary data points in a seasonal
254 cycle. If SEASONAL and DEVSEASONAL are implicitly created, this argument for
255 those B<RRAs> is set automatically to the value specified by HWPREDICT. If
256 they are explicity created, the creator should verify that all three
257 I<seasonal period> arguments agree.
258
259 I<alpha> is the adaptation parameter of the intercept (or baseline)
260 coefficient in the Holt-Winters Forecasting algorithm. See L<rrdtool> for a
261 description of this algorithm. I<alpha> must lie between 0 and 1. A value
262 closer to 1 means that more recent observations carry greater weight in
263 predicting the baseline component of the forecast. A value closer to 0 mean
264 that past history carries greater weight in predicted the baseline
265 component.
266
267 I<beta> is the adaption parameter of the slope (or linear trend) coefficient
268 in the Holt-Winters Forecating algorihtm. I<beta> must lie between 0 and 1
269 and plays the same role as I<alpha> with respect to the predicted linear
270 trend.
271
272 I<gamma> is the adaption parameter of the seasonal coefficients in the
273 Holt-Winters Forecasting algorithm (HWPREDICT) or the adaption parameter in
274 the exponential smoothing update of the seasonal deviations. It must lie
275 between 0 and 1. If the SEASONAL and DEVSEASONAL B<RRAs> are created
276 implicitly, they will both have the same value for I<gamma>: the value
277 specified for the HWPREDICT I<alpha> argument. Note that because there is
278 one seasonal coefficient (or deviation) for each time point during the
279 seasonal cycle, the adaption rate is much slower than the baseline. Each
280 seasonal coefficient is only updated (or adapts) when the observed value
281 occurs at the offset in the seasonal cycle corresponding to that
282 coefficient.
283
284 If SEASONAL and DEVSEASONAL B<RRAs> are created explicity, I<gamma> need not
285 be the same for both. Note that I<gamma> can also be changed via the
286 B<rrdtool> I<tune> command.
287
288 I<rra num> provides the links between related B<RRAs>. If HWPREDICT is
289 specified alone and the other B<RRAs> created implicitly, then there is no
290 need to worry about this argument. If B<RRAs> are created explicitly, then
291 pay careful attention to this argument. For each B<RRA> which includes this
292 argument, there is a dependency between that B<RRA> and another B<RRA>. The
293 I<rra num> argument is the 1-based index in the order of B<RRA> creation
294 (that is, the order they appear in the I<create> command). The dependent
295 B<RRA> for each B<RRA> requiring the I<rra num> argument is listed here:
296
297 =over 4
298
299 =item *
300
301 HWPREDICT I<rra num> is the index of the SEASONAL B<RRA>.
302
303 =item * 
304
305 SEASONAL I<rra num> is the index of the HWPREDICT B<RRA>.
306
307 =item * 
308
309 DEVPREDICT I<rra num> is the index of the DEVSEASONAL B<RRA>.
310
311 =item *
312
313 DEVSEASONAL I<rra num> is the index of the HWPREDICT B<RRA>.
314
315 =item * 
316
317 FAILURES I<rra num> is the index of the DEVSEASONAL B<RRA>.
318
319 =back
320
321 I<threshold> is the minimum number of violations (observed values outside
322 the confidence bounds) within a window that constitutes a failure. If the
323 FAILURES B<RRA> is implicitly created, the default value is 7.
324
325 I<window length> is the number of time points in the window. Specify an
326 integer greater than or equal to the threshold and less than or equal to 28.
327 The time interval this window represents depends on the interval between
328 primary data points. If the FAILURES B<RRA> is implicity created, the
329 default value is 9.
330
331 =head1 The HEARTBEAT and the STEP
332
333 Here is an explanation by Don Baarda on the inner workings of rrdtool.
334 It may help you to sort out why all this *UNKNOWN* data is popping
335 up in your databases:
336
337 RRD gets fed samples at arbitrary times. From these it builds Primary
338 Data Points (PDPs) at exact times every "step" interval. The PDPs are
339 then accumulated into RRAs.
340
341 The "heartbeat" defines the maximum acceptable interval between
342 samples. If the interval between samples is less than "heartbeat",
343 then an average rate is calculated and applied for that interval. If
344 the interval between samples is longer than "heartbeat", then that
345 entire interval is considered "unknown". Note that there are other
346 things that can make a sample interval "unknown", such as the rate
347 exceeding limits, or even an "unknown" input sample.
348
349 The known rates during a PDP's "step" interval are used to calculate
350 an average rate for that PDP. Also, if the total "unknown" time during
351 the "step" interval exceeds the "heartbeat", the entire PDP is marked
352 as "unknown". This means that a mixture of known and "unknown" sample
353 time in a single PDP "step" may or may not add up to enough "unknown"
354 time to exceed "heartbeat" and hence mark the whole PDP "unknown". So
355 "heartbeat" is not only the maximum acceptable interval between
356 samples, but also the maximum acceptable amount of "unknown" time per
357 PDP (obviously this is only significant if you have "heartbeat" less
358 than "step").
359
360 The "heartbeat" can be short (unusual) or long (typical) relative to
361 the "step" interval between PDPs. A short "heartbeat" means you
362 require multiple samples per PDP, and if you don't get them mark the
363 PDP unknown. A long heartbeat can span multiple "steps", which means
364 it is acceptable to have multiple PDPs calculated from a single
365 sample. An extreme example of this might be a "step" of 5mins and a
366 "heartbeat" of one day, in which case a single sample every day will
367 result in all the PDPs for that entire day period being set to the
368 same average rate. I<-- Don Baarda E<lt>don.baarda@baesystems.comE<gt>>
369
370
371 =head1 HOW TO MEASURE
372
373 Here are a few hints on how to measure:
374
375 =over
376
377
378 =item Temperature
379
380 Normally you have some type of meter you can read to get the temperature.
381 The temperature is not realy connected with a time. The only connection is
382 that the temperature reading happened at a certain time. You can use the
383 B<GAUGE> data source type for this. RRRtool will the record your reading
384 together with the time.
385
386 =item Mail Messages
387
388 Assume you have a methode to count the number of messages transported by
389 your mailserver in a certain amount of time, this give you data like '5
390 messages in the last 65 seconds'. If you look at the count of 5 like and
391 B<ABSOLUTE> datatype you can simply update the rrd with the number 5 and the
392 end time of your monitoring period. RRDtool will then record the number of
393 messages per second. If at some later stage you want to know the number of
394 messages transported in a day, you can get the average messages per second
395 from RRDtool for the day in question and multiply this number with the
396 number of seconds in a day. Because all math is run with Doubles, the
397 precision should be acceptable.
398
399 =item It's always a Rate
400
401 RRDtool stores rates in amount/second for COUNTER, DERIVE and ABSOLUTE data.
402 When you plot the data, you will get on the y axis amount/second which you
403 might be tempted to convert to absolute amount volume by multiplying by the
404 delta-time between the points. RRDtool plots continuous data, and as such is
405 not appropriate for plotting absolute volumes as for example "total bytes"
406 sent and received in a router. What you probably want is plot rates that you
407 can scale to for example bytes/hour or plot volumes with another tool that
408 draws bar-plots, where the delta-time is clear on the plot for each point
409 (such that when you read the graph you see for example GB on the y axis,
410 days on the x axis and one bar for each day).
411
412 =back
413
414
415 =head1 EXAMPLE
416
417 C<rrdtool create temperature.rrd --step 300 DS:temp:GAUGE:600:-273:5000
418 RRA:AVERAGE:0.5:1:1200 RRA:MIN:0.5:12:2400 RRA:MAX:0.5:12:2400
419 RRA:AVERAGE:0.5:12:2400>
420
421 This sets up an B<RRD> called F<temperature.rrd> which accepts one
422 temperature value every 300 seconds. If no new data is supplied for
423 more than 600 seconds, the temperature becomes I<*UNKNOWN*>.  The
424 minimum acceptable value is -273 and the maximum is 5000.
425
426 A few archives areas are also defined. The first stores the
427 temperatures supplied for 100 hours (1200 * 300 seconds = 100
428 hours). The second RRA stores the minimum temperature recorded over
429 every hour (12 * 300 seconds = 1 hour), for 100 days (2400 hours). The
430 third and the fourth RRA's do the same with the for the maximum and
431 average temperature, respectively.
432
433 =head1 EXAMPLE 2
434
435 C<rrdtool create monitor.rrd --step 300 
436 DS:ifOutOctets:COUNTER:1800:0:4294967295
437 RRA:AVERAGE:0.5:1:2016
438 RRA:HWPREDICT:1440:0.1:0.0035:288>
439
440 This example is a monitor of a router interface. The first B<RRA> tracks the
441 traffic flow in octects; the second B<RRA> generates the specialized
442 functions B<RRAs> for aberrant behavior detection. Note that the I<rra num>
443 argument of HWPREDICT is missing, so the other B<RRAs> will be implicitly be
444 created with default parameter values. In this example, the forecasting
445 algorithm baseline adapts quickly; in fact the most recent one hour of
446 observations (each at 5 minute intervals) account for 75% of the baseline
447 prediction. The linear trend forecast adapts much more slowly. Observations
448 made in during the last day (at 288 observations per day) account for only
449 65% of the predicted linear trend. Note: these computations rely on an
450 exponential smoothing formula described in a forthcoming LISA 2000 paper.
451
452 The seasonal cycle is one day (288 data points at 300 second intervals), and
453 the seasonal adaption paramter will be set to 0.1. The RRD file will store 5
454 days (1440 data points) of forecasts and deviation predictions before wrap
455 around. The file will store 1 day (a seasonal cycle) of 0-1 indicators in
456 the FAILURES B<RRA>.
457
458 The same RRD file and B<RRAs> are created with the following command, which explicitly
459 creates all specialized function B<RRAs>.
460
461 C<rrdtool create monitor.rrd --step 300 
462 DS:ifOutOctets:COUNTER:1800:0:4294967295
463 RRA:AVERAGE:0.5:1:2016
464 RRA:HWPREDICT:1440:0.1:0.0035:288:3
465 RRA:SEASONAL:288:0.1:2
466 RRA:DEVPREDICT:1440:5
467 RRA:DEVSEASONAL:288:0.1:2
468 RRA:FAILURES:288:7:9:5>
469
470 Of course, explicit creation need not replicate implicit create, a number of arguments 
471 could be changed.
472
473 =head1 EXAMPLE 3
474
475 C<rrdtool create proxy.rrd --step 300 
476 DS:TotalRequests:DERIVE:1800:0:U
477 DS:AccumDuration:DERIVE:1800:0:U
478 DS:AvgReqDuration:COMPUTE:AccumDuration,TotalRequests,0,EQ,1,TotalRequests,IF,/
479 RRA:AVERAGE:0.5:1:2016>
480
481 This example is monitoring the average request duration during each 300 sec 
482 interval for requests processed by a web proxy during the interval.
483 In this case, the proxy exposes two counters, the number of requests
484 processed since boot and the total cumulative duration of all processed
485 requests. Clearly these counters both have some rollover point, but using the
486 DERIVE data source also handles the reset that occurs when the web proxy is
487 stopped and restarted.
488
489 In the B<RRD>, the first data source stores the requests per second rate
490 during the interval. The second data source stores the total duration of all
491 requests processed during the interval divided by 300. The COMPUTE data source
492 divides each PDP of the AccumDuration by the corresponding PDP of
493 TotalRequests and stores the average request duration. The remainder of the
494 RPN expression handles the divide by zero case.
495
496 =head1 AUTHOR
497
498 Tobias Oetiker E<lt>oetiker@ee.ethz.chE<gt>