Attached a patch for the rrd-tool LIBDBI integration with the following improvements:
[rrdtool.git] / doc / rrdcached.pod
1 =pod
2
3 =head1 NAME
4
5 rrdcached - Data caching daemon for rrdtool
6
7 =head1 SYNOPSIS
8
9 B<rrdcached>
10 [B<-l/-L>E<nbsp>I<address>]
11 [B<-w>E<nbsp>I<timeout>]
12 [B<-z>E<nbsp>I<delay>]
13 [B<-f>E<nbsp>I<timeout>]
14 [B<-p>E<nbsp>I<pid_file>]
15 [B<-t>E<nbsp>I<write_threads>]
16 [B<-j>E<nbsp>I<journal_dir>]
17 [-F]
18 [B<-b>E<nbsp>I<base_dir>E<nbsp>[B<-B>]]
19
20 =head1 DESCRIPTION
21
22 B<rrdcached> is a daemon that receives updates to existing RRD files,
23 accumulates them and, if enough have been received or a defined time has
24 passed, writes the updates to the RRD file. A I<flush> command may be used to
25 force writing of values to disk, so that graphing facilities and similar can
26 work with up-to-date data.
27
28 The daemon was written with big setups in mind. Those setups usually run into
29 IOE<nbsp>related problems sooner or later for reasons that are beyond the scope
30 of this document. Check the wiki at the RRDTool homepage for details. Also
31 check L<SECURITY CONSIDERATIONS> below before using this daemon! A detailed
32 description of how the daemon operates can be found in the L<HOW IT WORKS>
33 section below.
34
35 =head1 OPTIONS
36
37 =over 4
38
39 =item B<-l> I<address>
40
41 Tells the daemon to bind to I<address> and accept incoming connections on that
42 socket. If I<address> begins with C<unix:>, everything following that prefix is
43 interpreted as the path to a UNIX domain socket. Otherwise the address or node
44 name are resolved using L<getaddrinfo>.
45
46 For network sockets, a port may be specified by using the form
47 C<B<[>I<address>B<]:>I<port>>. If the address is an IPv4 address or a fully
48 qualified domain name (i.E<nbsp>e. the address contains at least one dot
49 (C<.>)), the square brackets can be omitted, resulting in the (simpler)
50 C<I<address>B<:>I<port>> pattern.. The default port is B<42217/udp>.
51
52 The following formats are accepted. Please note that the address of the UNIX
53 domain socket B<must> start with a slash in the second case!
54
55    unix:</path/to/unix.sock>
56    /<path/to/unix.sock>
57    <hostname-or-ip>
58    [<hostname-or-ip>]:<port>
59    <hostname-or-ipv4>:<port>
60
61 If the B<-l> option is not specified the default address,
62 C<unix:/tmp/rrdcached.sock>, will be used.
63
64 =item B<-L> I<address>
65
66 Same as B<-l>, except creates a low-privilege socket.  See B<SECURITY
67 CONSIDERATIONS> for more information.
68
69 =item B<-w> I<timeout>
70
71 Data is written to disk every I<timeout> seconds. If this option is not
72 specified the default interval of 300E<nbsp>seconds will be used.
73
74 =item B<-z> I<delay>
75
76 If specified, rrdcached will delay writing of each RRD for a random number
77 of seconds in the rangeE<nbsp>[0,I<delay>).  This will avoid too many
78 writes being queued simultaneously.  This value should be no greater than
79 the value specified in B<-w>.  By default, there is no delay.
80
81 =item B<-f> I<timeout>
82
83 Every I<timeout> seconds the entire cache is searched for old values which are
84 written to disk. This only concerns files to which updates have stopped, so
85 setting this to a high value, such as 3600E<nbsp>seconds, is acceptable in most
86 cases. This timeout defaults to 3600E<nbsp>seconds.
87
88 =item B<-p> I<file>
89
90 Sets the name and location of the PID-file. If not specified, the default,
91 C<I<$localststedir>/run/rrdcached.pid> will be used.
92
93 =item B<-t> I<write_threads>
94
95 Specifies the number of threads used for writing RRD files.  The default
96 isE<nbsp>4.  Increasing this number will allow rrdcached to have more
97 simultaneous I/O requests into the kernel.  This may allow the kernel to
98 re-order disk writes, resulting in better disk throughput.
99
100 =item B<-j> I<dir>
101
102 Write updates to a journal in I<dir>.  In the event of a program or system
103 crash, this will allow the daemon to write any updates that were pending
104 at the time of the crash.
105
106 On startup, the daemon will check for journal files in this directory.  If
107 found, all updates therein will be read into memory before the daemon
108 starts accepting new connections.
109
110 The journal will be rotated with the same frequency as the flush timer
111 given by B<-f>.
112
113 When journaling is enabled, the daemon will use a fast shutdown procedure.
114 Rather than flushing all files to disk, it will make sure the journal is
115 properly written and exit immediately.  Although the RRD data files are
116 not fully up-to-date, no information is lost; all pending updates will be
117 replayed from the journal next time the daemon starts up.
118
119 To disable fast shutdown, use the B<-F> option.
120
121 =item B<-F>
122
123 ALWAYS flush all updates to the RRD data files when the daemon is shut
124 down, regardless of journal setting.
125
126 =item B<-b> I<dir>
127
128 The daemon will change into a specific directory at startup. All files passed
129 to the daemon, that are specified by a B<relative> path, will be interpreted
130 to be relative to this directory. If not given the default, C</tmp>, will be
131 used.
132
133   +------------------------+------------------------+
134   ! Command line           ! File updated           !
135   +------------------------+------------------------+
136   ! foo.rrd                ! /tmp/foo.rrd           !
137   ! foo/bar.rrd            ! /tmp/foo/bar.rrd       !
138   ! /var/lib/rrd/foo.rrd   ! /var/lib/rrd/foo.rrd   !
139   +------------------------+------------------------+
140   Paths given on the command  line and paths actually
141   updated by the daemon,  assuming the base directory
142   "/tmp".
143
144 B<WARNING:> The paths up to and including the base directory B<MUST NOT BE>
145 symbolic links.  In other words, if the base directory is
146 specified as:
147
148     -b /base/dir/somewhere
149
150 ... then B<NONE> of the following should be symbolic links:
151
152     /base
153     /base/dir
154     /base/dir/somewhere
155
156 =item B<-B>
157
158 Only permit writes into the base directory specified in B<-b> (and any
159 sub-directories).  This does B<NOT> detect symbolic links.  Paths
160 containing C<../> will also be blocked.
161
162 =back
163
164 =head1 AFFECTED RRDTOOL COMMANDS
165
166 The following commands may be made aware of the B<rrdcached> using the command
167 line argument B<--daemon> or the environment variable B<RRDCACHED_ADDRESS>:
168
169 =over 4
170
171 =item B<dump>
172
173 =item B<fetch>
174
175 =item B<flush>
176
177 =item B<graph>
178
179 =item B<graphv>
180
181 =item B<info>
182
183 =item B<last>
184
185 =item B<lastupdate>
186
187 =item B<update>
188
189 =item B<xport>
190
191 =back
192
193 The B<update> command can send values to the daemon instead of writing them to
194 the disk itself. All other commands can send a B<FLUSH> command (see below) to
195 the daemon before accessing the files, so they work with up-to-date data even
196 if the cache timeout is large.
197
198 =head1 ERROR REPORTING
199
200 The daemon reports errors in one of two ways: During startup, error messages
201 are printed to C<STDERR>. One of the steps when starting up is to fork to the
202 background and closing C<STDERR> - after this writing directly to the user is
203 no longer possible. Once this has happened, the daemon will send log messages
204 to the system logging daemon using L<syslog(3)>. The facility used is
205 C<LOG_DAEMON>.
206
207 =head1 HOW IT WORKS
208
209 When receiving an update, B<rrdcached> does not write to disk but looks for an
210 entry for that file in its internal tree. If not found, an entry is created
211 including the current time (called "First" in the diagram below). This time is
212 B<not> the time specified on the command line but the time the operating system
213 considers to be "now". The value and time of the value (called "Time" in the
214 diagram below) are appended to the tree node.
215
216 When appending a value to a tree node, it is checked whether it's time to write
217 the values to disk. Values are written to disk if
218 S<C<now() - First E<gt>= timeout>>, where C<timeout> is the timeout specified
219 using the B<-w> option, see L<OPTIONS>. If the values are "old enough" they
220 will be enqueued in the "update queue", i.E<nbsp>e. they will be appended to
221 the linked list shown below.  Because the tree nodes and the elements of the
222 linked list are the same data structures in memory, any update to a file that
223 has already been enqueued will be written with the next write to the RRD file,
224 too.
225
226 A separate "update thread" constantly dequeues the first element in the update
227 queue and writes all its values to the appropriate file. So as long as the
228 update queue is not empty files are written at the highest possible rate.
229
230 Since the timeout of files is checked only when new values are added to the
231 file, "dead" files, i.E<nbsp>e. files that are not updated anymore, would never
232 be written to disk. Therefore, every now and then, controlled by the B<-f>
233 option, the entire tree is walked and all "old" values are enqueued. Since this
234 only affects "dead" files and walking the tree is relatively expensive, you
235 should set the "flush interval" to a reasonably high value. The default is
236 3600E<nbsp>seconds (one hour).
237
238 The downside of caching values is that they won't show up in graphs generated
239 from the RRDE<nbsp>files. To get around this, the daemon provides the "flush
240 command" to flush specific files. This means that the file is inserted at the
241 B<head> of the update queue or moved there if it is already enqueued. The flush
242 command will return only after the file's pending updates have been written
243 to disk.
244
245  +------+   +------+                               +------+
246  ! head !   ! root !                               ! tail !
247  +---+--+   +---+--+                               +---+--+
248      !         /\                                      !
249      !        /  \                                     !
250      !       /\  /\                                    !
251      !      /\/\ \ `----------------- ... --------,    !
252      V     /      `-------,                       !    V
253  +---+----+---+    +------+-----+             +---+----+---+
254  ! File:  foo !    ! File:  bar !             ! File:  qux !
255  ! First: 101 !    ! First: 119 !             ! First: 180 !
256  ! Next:&bar -+--->! Next:&... -+---> ... --->! Next:NULL  !
257  | Prev:NULL  !<---+-Prev:&foo  !<--- ... ----+-Prev: &... !
258  +============+    +============+             +============+
259  ! Time:  100 !    ! Time:  120 !             ! Time:  180 !
260  ! Value:  10 !    ! Value: 0.1 !             ! Value: 2,2 !
261  +------------+    +------------+             +------------+
262  ! Time:  110 !    ! Time:  130 !             ! Time:  190 !
263  ! Value:  26 !    ! Value: 0.1 !             ! Value: 7,3 !
264  +------------+    +------------+             +------------+
265  :            :    :            :             :            :
266  +------------+    +------------+             +------------+
267  ! Time:  230 !    ! Time:  250 !             ! Time:  310 !
268  ! Value:  42 !    ! Value: 0.2 !             ! Value: 1,2 !
269  +------------+    +------------+             +------------+
270
271 The above diagram demonstrates:
272
273 =over
274
275 =item *
276
277 Files/values are stored in a (balanced) tree.
278
279 =item *
280
281 Tree nodes and entries in the update queue are the same data structure.
282
283 =item *
284
285 The local time ("First") and the time specified in updates ("Time") may differ.  
286
287 =item *
288
289 Timed out values are inserted at the "tail".
290
291 =item *
292
293 Explicitly flushed values are inserted at the "head".
294
295 =item *
296
297 ASCII art rocks.
298
299 =back
300
301 =head1 SECURITY CONSIDERATIONS
302
303 The client/server protocol does not have any authentication or
304 authorization mechanism.  Therefore, take care to restrict which users can
305 connect to the daemon.
306
307 Control sockets are divided into high-privilege (B<-l>) and low-privilege
308 (B<-L>) sockets.  High-privilege sockets accept all commands, whereas
309 low-privilege sockets accept only B<FLUSH>, B<STATS>, and B<HELP>.
310
311 For a multi-user environment where only certain users require read/write
312 access, the recommended configuration uses two sockets as follows:
313
314 =over
315
316 =item B<-l> I</protected/dir/rrd.sock>
317
318 Create a high-privilege unix-domain socket.  This should be protected with
319 the same Unix permissions that are used to protect the RRD files.  Updates
320 should be directed to this socket.
321
322 =item B<-L> I<127.0.0.1>
323
324 Create a low-privilege TCP socket listening on localhost.  All users on
325 the local system may use this to trigger FLUSH of individual files.  Users
326 with read-only access should be directed to this socket.
327
328 =back
329
330 If you (want to) use the network capability, i.E<nbsp>e. let the daemon bind to
331 an IPv4 or IPv6 socket, it is B<your> job to install a packet filter or similar
332 mechanism to prevent unauthorized connections. Unless you have a dedicated VLAN
333 or VPN for this, using the network option is probably a bad idea!
334
335 The daemon will blindly write to any file it gets told, so you really should
336 create a separate user just for this daemon. Also it does not do any sanity
337 checks, so if it gets told to write values for a time far in the future, your
338 files will be messed up good!
339
340 You have been warned.
341
342 =head1 PROTOCOL
343
344 The daemon communicates with clients using a line based ASCII protocol which is
345 easy to read and easy to type. This makes it easy for scripts to implement the
346 protocol and possible for users to use L<telnet> to connect to the daemon
347 and test stuff "by hand".
348
349 The protocol is line based, this means that each record consists of one or more
350 lines. A line is terminated by the line feed character C<0x0A>, commonly
351 written as C<\n>. In the examples below, this character will be written as
352 C<E<lt>LFE<gt>> ("line feed").
353
354 After the connection has been established, the client is expected to send a
355 "command". A command consists of the command keyword, possibly some arguments,
356 and a terminating newline character. For a list of commands, see
357 L<Valid Commands> below.
358
359 Example:
360
361   FLUSH /tmp/foo.rrd<LF>
362
363 The daemon answers with a line consisting of a status code and a short status
364 message, separated by one or more space characters. A negative status code
365 signals an error, a positive status code or zero signal success. If the status
366 code is greater than zero, it indicates the number of lines that follow the
367 status line.
368
369 Examples:
370
371  0 Success<LF>
372
373  2 Two lines follow<LF>
374  This is the first line<LF>
375  And this is the second line<LF>
376
377 =head2 Valid Commands
378
379 The following commands are understood by the daemon:
380
381 =over 4
382
383 =item B<FLUSH> I<filename>
384
385 Causes the daemon to put I<filename> to the B<head> of the update queue
386 (possibly moving it there if the node is already enqueued). The answer will be
387 sent B<after> the node has been dequeued.
388
389 =item B<FLUSHALL>
390
391 Causes the daemon to start flushing ALL pending values to disk.  This
392 returns immediately, even though the writes may take a long time.
393
394 =item B<PENDING> I<filename>
395
396 Shows any "pending" updates for a file, in order.  The updates shown have
397 not yet been written to the underlying RRD file.
398
399 =item B<FORGET> I<filename>
400
401 Removes I<filename> from the cache.  Any pending updates B<WILL BE LOST>.
402
403 =item B<QUEUE>
404
405 Shows the files that are on the output queue.  Returns zero or more lines
406 in the following format, where E<lt>num_valsE<gt> is the number of values
407 to be written for the E<lt>fileE<gt>:
408
409     <num_vals> <file>
410
411 =item B<HELP> [I<command>]
412
413 Returns a short usage message. If no command is given, or I<command> is
414 B<HELP>, a list of commands supported by the daemon is returned. Otherwise a
415 short description, possibly containing a pointer to a manual page, is returned.
416 Obviously, this is meant for interactive usage and the format in which the
417 commands and usage summaries are returned is not well defined.
418
419 =item B<STATS>
420
421 Returns a list of metrics which can be used to measure the daemons performance
422 and check its status. For a description of the values returned, see
423 L<Performance Values> below.
424
425 The format in which the values are returned is similar to many other line based
426 protocols: Each value is printed on a separate line, each consisting of the
427 name of the value, a colon, one or more spaces and the actual value.
428
429 Example:
430
431  9 Statistics follow
432  QueueLength: 0
433  UpdatesReceived: 30
434  FlushesReceived: 2
435  UpdatesWritten: 13
436  DataSetsWritten: 390
437  TreeNodesNumber: 13
438  TreeDepth: 4
439  JournalBytes: 190
440  JournalRotate: 0
441
442 =item B<UPDATE> I<filename> I<values> [I<values> ...]
443
444 Adds more data to a filename. This is B<the> operation the daemon was designed
445 for, so describing the mechanism again is unnecessary. Read L<HOW IT WORKS>
446 above for a detailed explanation.
447
448 Note that rrdcached only accepts absolute timestamps in the update values.
449 Updates strings like "N:1:2:3" are automatically converted to absolute
450 time by the RRD client library before sending to rrdcached.
451
452 =item B<WROTE> I<filename>
453
454 This command is written to the journal after a file is successfully
455 written out to disk.  It is used during journal replay to determine which
456 updates have already been applied.  It is I<only> valid in the journal; it
457 is not accepted from the other command channels.
458
459 =item B<BATCH>
460
461 This command initiates the bulk load of multiple commands.  This is
462 designed for installations with extremely high update rates, since it
463 permits more than one command to be issued per read() and write().
464
465 All commands are executed just as they would be if given individually,
466 except for output to the user.  Messages indicating success are
467 suppressed, and error messages are delayed until the client is finished.
468
469 Command processing is finished when the client sends a dot (".") on its
470 own line.  After the client has finished, the server responds with an
471 error count and the list of error messages (if any).  Each error messages
472 indicates the number of the command to which it corresponds, and the error
473 message itself.  The first user command after B<BATCH> is command number one.
474
475     client:  BATCH
476     server:  0 Go ahead.  End with dot '.' on its own line.
477     client:  UPDATE x.rrd 1223661439:1:2:3            <--- command #1
478     client:  UPDATE y.rrd 1223661440:3:4:5            <--- command #2
479     client:  and so on...
480     client:  .
481     server:  2 Errors
482     server:  1 message for command 1
483     server:  12 message for command 12
484
485 =item B<QUIT>
486
487 Disconnect from rrdcached.
488
489 =back
490
491 =head2 Performance Values
492
493 The following counters are returned by the B<STATS> command:
494
495 =over 4
496
497 =item B<QueueLength> I<(unsigned 64bit integer)>
498
499 Number of nodes currently enqueued in the update queue.
500
501 =item B<UpdatesReceived> I<(unsigned 64bit integer)>
502
503 Number of UPDATE commands received.
504
505 =item B<FlushesReceived> I<(unsigned 64bit integer)>
506
507 Number of FLUSH commands received.
508
509 =item B<UpdatesWritten> I<(unsigned 64bit integer)>
510
511 Total number of updates, i.E<nbsp>e. calls to C<rrd_update_r>, since the
512 daemon was started.
513
514 =item B<DataSetsWritten> I<(unsigned 64bit integer)>
515
516 Total number of "data sets" written to disk since the daemon was
517 started. A data set is one or more values passed to the B<UPDATE>
518 command. For example: C<1223661439:123:456> is one data set with two
519 values. The term "data set" is used to prevent confusion whether
520 individual values or groups of values are counted.
521
522 =item B<TreeNodesNumber> I<(unsigned 64bit integer)>
523
524 Number of nodes in the cache.
525
526 =item B<TreeDepth> I<(unsigned 64bit integer)>
527
528 Depth of the tree used for fast key lookup.
529
530 =item B<JournalBytes> I<(unsigned 64bit integer)>
531
532 Total number of bytes written to the journal since startup.
533
534 =item B<JournalRotate> I<(unsigned 64bit integer)>
535
536 Number of times the journal has been rotated since startup.
537
538 =back
539
540 =head1 SIGNALS
541
542 =over 4
543
544 =item SIGINT and SIGTERM
545
546 The daemon exits normally on receipt of either of these signals.  Pending
547 updates are handled in accordance with the B<-j> and B<-F> options.
548
549 =item SIGUSR1
550
551 The daemon exits AFTER flushing all updates out to disk.  This may take a
552 while.
553
554 =item SIGUSR2
555
556 The daemon exits immediately, without flushing updates out to disk.
557 Pending updates will be replayed from the journal when the daemon starts
558 up again.  B<WARNING: if journaling (-j) is NOT enabled, any pending
559 updates WILL BE LOST>.
560
561 =back
562
563 =head1 BUGS
564
565 No known bugs at the moment.
566
567 =head1 SEE ALSO
568
569 L<rrdtool>, L<rrdgraph>
570
571 =head1 AUTHOR
572
573 B<rrdcached> and this manual page have been written by Florian Forster
574 E<lt>octoE<nbsp>atE<nbsp>verplant.orgE<gt>.
575
576 =head1 CONTRIBUTORS
577
578 kevin brintnall E<lt>kbrint@rufus.netE<gt>
579
580 =cut
581