Code

Obviously this will only work if rrdcached is running as root which in
[rrdtool-all.git] / program / doc / rrdcached.pod
1 =pod
3 =head1 NAME
5 rrdcached - Data caching daemon for rrdtool
7 =head1 SYNOPSIS
9 B<rrdcached>
10 [B<-P>E<nbsp>I<permissions>]
11 [B<-l>E<nbsp>I<address>]
12 [B<-s>E<nbsp>I<group>]
13 [B<-w>E<nbsp>I<timeout>]
14 [B<-z>E<nbsp>I<delay>]
15 [B<-f>E<nbsp>I<timeout>]
16 [B<-p>E<nbsp>I<pid_file>]
17 [B<-t>E<nbsp>I<write_threads>]
18 [B<-j>E<nbsp>I<journal_dir>]
19 [-F]
20 [-g]
21 [B<-b>E<nbsp>I<base_dir>E<nbsp>[B<-B>]]
23 =head1 DESCRIPTION
25 B<rrdcached> is a daemon that receives updates to existing RRD files,
26 accumulates them and, if enough have been received or a defined time has
27 passed, writes the updates to the RRD file. A I<flush> command may be used to
28 force writing of values to disk, so that graphing facilities and similar can
29 work with up-to-date data.
31 The daemon was written with big setups in mind. Those setups usually run into
32 IOE<nbsp>related problems sooner or later for reasons that are beyond the scope
33 of this document. Check the wiki at the RRDtool homepage for details. Also
34 check L</"SECURITY CONSIDERATIONS"> below before using this daemon! A detailed
35 description of how the daemon operates can be found in the L</"HOW IT WORKS">
36 section below.
38 =head1 OPTIONS
40 =over 4
42 =item B<-l> I<address>
44 Tells the daemon to bind to I<address> and accept incoming connections on that
45 socket. If I<address> begins with C<unix:>, everything following that prefix is
46 interpreted as the path to a UNIX domain socket. Otherwise the address or node
47 name are resolved using getaddrinfo.
49 For network sockets, a port may be specified by using the form
50 C<B<[>I<address>B<]:>I<port>>. If the address is an IPv4 address or a fully
51 qualified domain name (i.E<nbsp>e. the address contains at least one dot
52 (C<.>)), the square brackets can be omitted, resulting in the (simpler)
53 C<I<address>B<:>I<port>> pattern. The default port is B<42217/udp>. If you
54 specify a network socket, it is mandatory to read the
55 L</"SECURITY CONSIDERATIONS"> section.
57 The following formats are accepted. Please note that the address of the UNIX
58 domain socket B<must> start with a slash in the second case!
60    unix:</path/to/unix.sock>
61    /<path/to/unix.sock>
62    <hostname-or-ip>
63    [<hostname-or-ip>]:<port>
64    <hostname-or-ipv4>:<port>
66 If the B<-l> option is not specified the default address,
67 C<unix:/tmp/rrdcached.sock>, will be used.
69 =item B<-s> I<id>
71 Set the group permissions of the UNIX domain socket. The option accepts either
72 a numeric group id or group name. That group will then have both read and write
73 permissions to the socket and therefore able to send commands to the daemon. This
74 may be useful in cases where you cannot easily run all RRD processes with the same
75 user privileges (e.g. graph generating CGI scripts that typically run in the
76 permission context of the web server).
78 =item B<-P> I<command>[,I<command>[,...]]
80 Specifies the commands accepted via a network socket. This allows
81 administrators of I<RRDCacheD> to control the actions accepted from various
82 sources.
84 The arguments given to the B<-P> option is a comma separated list of commands.
85 For example, to allow the C<FLUSH> and C<PENDING> commands one could specify:
87   rrdcached -P FLUSH,PENDING $MORE_ARGUMENTS
89 The B<-P> option effects the I<following> socket addresses (the following B<-l>
90 options). In the following example, only the IPv4 network socket (address
91 C<10.0.0.1>) will be restricted to the C<FLUSH> and C<PENDING> commands:
93   rrdcached -l unix:/some/path -P FLUSH,PENDING -l 10.0.0.1
95 A complete list of available commands can be found in the section
96 L</"Valid Commands"> below. There are two minor special exceptions:
98 =over 4
100 =item *
102 The C<HELP> and C<QUIT> commands are always allowed.
104 =item *
106 If the C<BATCH> command is accepted, the B<.>E<nbsp>command will automatically
107 be accepted, too.
109 =back
111 Please also read L</"SECURITY CONSIDERATIONS"> below.
113 =item B<-w> I<timeout>
115 Data is written to disk every I<timeout> seconds. If this option is not
116 specified the default interval of 300E<nbsp>seconds will be used.
118 =item B<-z> I<delay>
120 If specified, rrdcached will delay writing of each RRD for a random number
121 of seconds in the rangeE<nbsp>[0,I<delay>).  This will avoid too many
122 writes being queued simultaneously.  This value should be no greater than
123 the value specified in B<-w>.  By default, there is no delay.
125 =item B<-f> I<timeout>
127 Every I<timeout> seconds the entire cache is searched for old values which are
128 written to disk. This only concerns files to which updates have stopped, so
129 setting this to a high value, such as 3600E<nbsp>seconds, is acceptable in most
130 cases. This timeout defaults to 3600E<nbsp>seconds.
132 =item B<-p> I<file>
134 Sets the name and location of the PID-file. If not specified, the default,
135 C<I<$localststedir>/run/rrdcached.pid> will be used.
137 =item B<-t> I<write_threads>
139 Specifies the number of threads used for writing RRD files.  The default
140 isE<nbsp>4.  Increasing this number will allow rrdcached to have more
141 simultaneous I/O requests into the kernel.  This may allow the kernel to
142 re-order disk writes, resulting in better disk throughput.
144 =item B<-j> I<dir>
146 Write updates to a journal in I<dir>.  In the event of a program or system
147 crash, this will allow the daemon to write any updates that were pending
148 at the time of the crash.
150 On startup, the daemon will check for journal files in this directory.  If
151 found, all updates therein will be read into memory before the daemon
152 starts accepting new connections.
154 The journal will be rotated with the same frequency as the flush timer
155 given by B<-f>.
157 When journaling is enabled, the daemon will use a fast shutdown procedure.
158 Rather than flushing all files to disk, it will make sure the journal is
159 properly written and exit immediately.  Although the RRD data files are
160 not fully up-to-date, no information is lost; all pending updates will be
161 replayed from the journal next time the daemon starts up.
163 To disable fast shutdown, use the B<-F> option.
165 =item B<-F>
167 ALWAYS flush all updates to the RRD data files when the daemon is shut
168 down, regardless of journal setting.
170 =item B<-g>
172 Run in the foreground.  The daemon will not fork().
174 =item B<-b> I<dir>
176 The daemon will change into a specific directory at startup. All files passed
177 to the daemon, that are specified by a B<relative> path, will be interpreted
178 to be relative to this directory. If not given the default, C</tmp>, will be
179 used.
181   +------------------------+------------------------+
182   ! Command line           ! File updated           !
183   +------------------------+------------------------+
184   ! foo.rrd                ! /tmp/foo.rrd           !
185   ! foo/bar.rrd            ! /tmp/foo/bar.rrd       !
186   ! /var/lib/rrd/foo.rrd   ! /var/lib/rrd/foo.rrd   !
187   +------------------------+------------------------+
188   Paths given on the command  line and paths actually
189   updated by the daemon,  assuming the base directory
190   "/tmp".
192 B<WARNING:> The paths up to and including the base directory B<MUST NOT BE>
193 symbolic links.  In other words, if the base directory is
194 specified as:
196     -b /base/dir/somewhere
198 ... then B<NONE> of the following should be symbolic links:
200     /base
201     /base/dir
202     /base/dir/somewhere
204 =item B<-B>
206 Only permit writes into the base directory specified in B<-b> (and any
207 sub-directories).  This does B<NOT> detect symbolic links.  Paths
208 containing C<../> will also be blocked.
210 =back
212 =head1 AFFECTED RRDTOOL COMMANDS
214 The following commands may be made aware of the B<rrdcached> using the command
215 line argument B<--daemon> or the environment variable B<RRDCACHED_ADDRESS>:
217 =over
219 =item *
221 dump
223 =item *
225 fetch
227 =item *
229 flush
231 =item *
233 graph
235 =item *
237 graphv
239 =item *
241 info
243 =item *
245 last
247 =item *
249 lastupdate
251 =item *
253 update
255 =item *
257 xport
259 =back
261 The B<update> command can send values to the daemon instead of writing them to
262 the disk itself. All other commands can send a B<FLUSH> command (see below) to
263 the daemon before accessing the files, so they work with up-to-date data even
264 if the cache timeout is large.
266 =head1 ERROR REPORTING
268 The daemon reports errors in one of two ways: During startup, error messages
269 are printed to C<STDERR>. One of the steps when starting up is to fork to the
270 background and closing C<STDERR> - after this writing directly to the user is
271 no longer possible. Once this has happened, the daemon will send log messages
272 to the system logging daemon using syslog(3). The facility used is
273 C<LOG_DAEMON>.
275 =head1 HOW IT WORKS
277 When receiving an update, B<rrdcached> does not write to disk but looks for an
278 entry for that file in its internal tree. If not found, an entry is created
279 including the current time (called "First" in the diagram below). This time is
280 B<not> the time specified on the command line but the time the operating system
281 considers to be "now". The value and time of the value (called "Time" in the
282 diagram below) are appended to the tree node.
284 When appending a value to a tree node, it is checked whether it's time to write
285 the values to disk. Values are written to disk if
286 S<C<now() - First E<gt>= timeout>>, where C<timeout> is the timeout specified
287 using the B<-w> option, see L</OPTIONS>. If the values are "old enough" they
288 will be enqueued in the "update queue", i.E<nbsp>e. they will be appended to
289 the linked list shown below.  Because the tree nodes and the elements of the
290 linked list are the same data structures in memory, any update to a file that
291 has already been enqueued will be written with the next write to the RRD file,
292 too.
294 A separate "update thread" constantly dequeues the first element in the update
295 queue and writes all its values to the appropriate file. So as long as the
296 update queue is not empty files are written at the highest possible rate.
298 Since the timeout of files is checked only when new values are added to the
299 file, "dead" files, i.E<nbsp>e. files that are not updated anymore, would never
300 be written to disk. Therefore, every now and then, controlled by the B<-f>
301 option, the entire tree is walked and all "old" values are enqueued. Since this
302 only affects "dead" files and walking the tree is relatively expensive, you
303 should set the "flush interval" to a reasonably high value. The default is
304 3600E<nbsp>seconds (one hour).
306 The downside of caching values is that they won't show up in graphs generated
307 from the RRDE<nbsp>files. To get around this, the daemon provides the "flush
308 command" to flush specific files. This means that the file is inserted at the
309 B<head> of the update queue or moved there if it is already enqueued. The flush
310 command will return only after the file's pending updates have been written
311 to disk.
313  +------+   +------+                               +------+
314  ! head !   ! root !                               ! tail !
315  +---+--+   +---+--+                               +---+--+
316      !         /\                                      !
317      !        /  \                                     !
318      !       /\  /\                                    !
319      !      /\/\ \ `----------------- ... --------,    !
320      V     /      `-------,                       !    V
321  +---+----+---+    +------+-----+             +---+----+---+
322  ! File:  foo !    ! File:  bar !             ! File:  qux !
323  ! First: 101 !    ! First: 119 !             ! First: 180 !
324  ! Next:&bar -+--->! Next:&... -+---> ... --->! Next:NULL  !
325  | Prev:NULL  !<---+-Prev:&foo  !<--- ... ----+-Prev: &... !
326  +============+    +============+             +============+
327  ! Time:  100 !    ! Time:  120 !             ! Time:  180 !
328  ! Value:  10 !    ! Value: 0.1 !             ! Value: 2,2 !
329  +------------+    +------------+             +------------+
330  ! Time:  110 !    ! Time:  130 !             ! Time:  190 !
331  ! Value:  26 !    ! Value: 0.1 !             ! Value: 7,3 !
332  +------------+    +------------+             +------------+
333  :            :    :            :             :            :
334  +------------+    +------------+             +------------+
335  ! Time:  230 !    ! Time:  250 !             ! Time:  310 !
336  ! Value:  42 !    ! Value: 0.2 !             ! Value: 1,2 !
337  +------------+    +------------+             +------------+
339 The above diagram demonstrates:
341 =over
343 =item *
345 Files/values are stored in a (balanced) tree.
347 =item *
349 Tree nodes and entries in the update queue are the same data structure.
351 =item *
353 The local time ("First") and the time specified in updates ("Time") may differ.  
355 =item *
357 Timed out values are inserted at the "tail".
359 =item *
361 Explicitly flushed values are inserted at the "head".
363 =item *
365 ASCII art rocks.
367 =back
369 =head1 SECURITY CONSIDERATIONS
371 =head2 Authentication
373 There is no authentication.
375 The client/server protocol does not yet have any authentication mechanism. It
376 is likely that authentication and encryption will be added in a future version,
377 but for the time being it is the administrator's responsibility to secure the
378 traffic from/to the daemon!
380 It is highly recommended to install a packet filter or similar mechanism to
381 prevent unauthorized connections. Unless you have a dedicated VLAN or VPN for
382 this, using network sockets is probably a bad idea!
384 =head2 Authorization
386 There is minimal per-socket authorization.
388 Authorization is currently done on a per-socket basis. That means each socket
389 has a list of commands it will accept and it will accept. It will accept only
390 those commands explicitly listed but it will (currently) accept these commands
391 from anyone reaching the socket.
393 If the networking sockets are to be used, it is necessary to restrict the
394 accepted commands to those needed by external clients. If, for example,
395 external clients want to draw graphs of the cached data, they should only be
396 allowed to use the C<FLUSH> command.
398 =head2 Encryption
400 There is no encryption.
402 Again, this may be added in the future, but for the time being it is your job
403 to keep your private data private. Install a VPN or an encrypted tunnel if you
404 statistics are confidential!
406 =head2 Sanity checking
408 There is no sanity checking.
410 The daemon will blindly write to any file it gets told, so you really should
411 create a separate user just for this daemon. Also it does not do any sanity
412 checks, so if it gets told to write values for a time far in the future, your
413 files will be messed up good!
415 =head2 Conclusion
417 =over 4
419 =item *
421 Security is the job of the administrator.
423 =item *
425 We recommend to allow write access via UNIX domain sockets only.
427 =item *
429 You have been warned.
431 =back
433 =head1 PROTOCOL
435 The daemon communicates with clients using a line based ASCII protocol which is
436 easy to read and easy to type. This makes it easy for scripts to implement the
437 protocol and possible for users to use telnet to connect to the daemon
438 and test stuff "by hand".
440 The protocol is line based, this means that each record consists of one or more
441 lines. A line is terminated by the line feed character C<0x0A>, commonly
442 written as C<\n>. In the examples below, this character will be written as
443 C<E<lt>LFE<gt>> ("line feed").
445 After the connection has been established, the client is expected to send a
446 "command". A command consists of the command keyword, possibly some arguments,
447 and a terminating newline character. For a list of commands, see
448 L</"Valid Commands"> below.
450 Example:
452   FLUSH /tmp/foo.rrd<LF>
454 The daemon answers with a line consisting of a status code and a short status
455 message, separated by one or more space characters. A negative status code
456 signals an error, a positive status code or zero signal success. If the status
457 code is greater than zero, it indicates the number of lines that follow the
458 status line.
460 Examples:
462  0 Success<LF>
464  2 Two lines follow<LF>
465  This is the first line<LF>
466  And this is the second line<LF>
468 =head2 Valid Commands
470 The following commands are understood by the daemon:
472 =over 4
474 =item B<FLUSH> I<filename>
476 Causes the daemon to put I<filename> to the B<head> of the update queue
477 (possibly moving it there if the node is already enqueued). The answer will be
478 sent B<after> the node has been dequeued.
480 =item B<FLUSHALL>
482 Causes the daemon to start flushing ALL pending values to disk.  This
483 returns immediately, even though the writes may take a long time.
485 =item B<PENDING> I<filename>
487 Shows any "pending" updates for a file, in order.  The updates shown have
488 not yet been written to the underlying RRD file.
490 =item B<FORGET> I<filename>
492 Removes I<filename> from the cache.  Any pending updates B<WILL BE LOST>.
494 =item B<QUEUE>
496 Shows the files that are on the output queue.  Returns zero or more lines
497 in the following format, where E<lt>num_valsE<gt> is the number of values
498 to be written for the E<lt>fileE<gt>:
500     <num_vals> <file>
502 =item B<HELP> [I<command>]
504 Returns a short usage message. If no command is given, or I<command> is
505 B<HELP>, a list of commands supported by the daemon is returned. Otherwise a
506 short description, possibly containing a pointer to a manual page, is returned.
507 Obviously, this is meant for interactive usage and the format in which the
508 commands and usage summaries are returned is not well defined.
510 =item B<STATS>
512 Returns a list of metrics which can be used to measure the daemons performance
513 and check its status. For a description of the values returned, see
514 L</"Performance Values"> below.
516 The format in which the values are returned is similar to many other line based
517 protocols: Each value is printed on a separate line, each consisting of the
518 name of the value, a colon, one or more spaces and the actual value.
520 Example:
522  9 Statistics follow
523  QueueLength: 0
524  UpdatesReceived: 30
525  FlushesReceived: 2
526  UpdatesWritten: 13
527  DataSetsWritten: 390
528  TreeNodesNumber: 13
529  TreeDepth: 4
530  JournalBytes: 190
531  JournalRotate: 0
533 =item B<UPDATE> I<filename> I<values> [I<values> ...]
535 Adds more data to a filename. This is B<the> operation the daemon was designed
536 for, so describing the mechanism again is unnecessary. Read L</"HOW IT WORKS">
537 above for a detailed explanation.
539 Note that rrdcached only accepts absolute timestamps in the update values.
540 Updates strings like "N:1:2:3" are automatically converted to absolute
541 time by the RRD client library before sending to rrdcached.
543 =item B<WROTE> I<filename>
545 This command is written to the journal after a file is successfully
546 written out to disk.  It is used during journal replay to determine which
547 updates have already been applied.  It is I<only> valid in the journal; it
548 is not accepted from the other command channels.
550 =item B<BATCH>
552 This command initiates the bulk load of multiple commands.  This is
553 designed for installations with extremely high update rates, since it
554 permits more than one command to be issued per read() and write().
556 All commands are executed just as they would be if given individually,
557 except for output to the user.  Messages indicating success are
558 suppressed, and error messages are delayed until the client is finished.
560 Command processing is finished when the client sends a dot (".") on its
561 own line.  After the client has finished, the server responds with an
562 error count and the list of error messages (if any).  Each error messages
563 indicates the number of the command to which it corresponds, and the error
564 message itself.  The first user command after B<BATCH> is command number one.
566     client:  BATCH
567     server:  0 Go ahead.  End with dot '.' on its own line.
568     client:  UPDATE x.rrd 1223661439:1:2:3            <--- command #1
569     client:  UPDATE y.rrd 1223661440:3:4:5            <--- command #2
570     client:  and so on...
571     client:  .
572     server:  2 Errors
573     server:  1 message for command 1
574     server:  12 message for command 12
576 =item B<QUIT>
578 Disconnect from rrdcached.
580 =back
582 =head2 Performance Values
584 The following counters are returned by the B<STATS> command:
586 =over 4
588 =item B<QueueLength> I<(unsigned 64bit integer)>
590 Number of nodes currently enqueued in the update queue.
592 =item B<UpdatesReceived> I<(unsigned 64bit integer)>
594 Number of UPDATE commands received.
596 =item B<FlushesReceived> I<(unsigned 64bit integer)>
598 Number of FLUSH commands received.
600 =item B<UpdatesWritten> I<(unsigned 64bit integer)>
602 Total number of updates, i.E<nbsp>e. calls to C<rrd_update_r>, since the
603 daemon was started.
605 =item B<DataSetsWritten> I<(unsigned 64bit integer)>
607 Total number of "data sets" written to disk since the daemon was
608 started. A data set is one or more values passed to the B<UPDATE>
609 command. For example: C<1223661439:123:456> is one data set with two
610 values. The term "data set" is used to prevent confusion whether
611 individual values or groups of values are counted.
613 =item B<TreeNodesNumber> I<(unsigned 64bit integer)>
615 Number of nodes in the cache.
617 =item B<TreeDepth> I<(unsigned 64bit integer)>
619 Depth of the tree used for fast key lookup.
621 =item B<JournalBytes> I<(unsigned 64bit integer)>
623 Total number of bytes written to the journal since startup.
625 =item B<JournalRotate> I<(unsigned 64bit integer)>
627 Number of times the journal has been rotated since startup.
629 =back
631 =head1 SIGNALS
633 =over 4
635 =item SIGINT and SIGTERM
637 The daemon exits normally on receipt of either of these signals.  Pending
638 updates are handled in accordance with the B<-j> and B<-F> options.
640 =item SIGUSR1
642 The daemon exits AFTER flushing all updates out to disk.  This may take a
643 while.
645 =item SIGUSR2
647 The daemon exits immediately, without flushing updates out to disk.
648 Pending updates will be replayed from the journal when the daemon starts
649 up again.  B<WARNING: if journaling (-j) is NOT enabled, any pending
650 updates WILL BE LOST>.
652 =back
654 =head1 BUGS
656 No known bugs at the moment.
658 =head1 SEE ALSO
660 L<rrdtool>, L<rrdgraph>
662 =head1 AUTHOR
664 Florian Forster E<lt>octoE<nbsp>atE<nbsp>verplant.orgE<gt>
666 Both B<rrdcached> and this manual page have been written by Florian.
668 =head1 CONTRIBUTORS
670 kevin brintnall E<lt>kbrint@rufus.netE<gt>
672 =cut