Code

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