d8d88c59e520de524a8d72fdc274d53baff24fcb
[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> [B<-l> I<address>] [B<-w> I<timeout>] [B<-z> I<delay>] [B<-f> I<timeout>] [B<-j> I<dir>]
10
11 =head1 DESCRIPTION
12
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.
18
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.
25
26 =head1 OPTIONS
27
28 =over 4
29
30 =item B<-l> I<address>
31
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>.
36
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>.
42
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!
45
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>
51
52 If the B<-l> option is not specified the default address,
53 C<unix:/tmp/rrdcached.sock>, will be used.
54
55 =item B<-w> I<timeout>
56
57 Data is written to disk every I<timeout> seconds. If this option is not
58 specified the default interval of 300E<nbsp>seconds will be used.
59
60 =item B<-z> I<delay>
61
62 If specified, rrdcached will delay writing of each RRD for a random number
63 of seconds in the rangeE<nbsp>[0,I<delay>).  This will avoid too many
64 writes being queued simultaneously.  This value should be no greater than
65 the value specified in B<-w>.  By default, there is no delay.
66
67 =item B<-f> I<timeout>
68
69 Every I<timeout> seconds the entire cache is searched for old values which are
70 written to disk. This only concerns files to which updates have stopped, so
71 setting this to a high value, such as 3600E<nbsp>seconds, is acceptable in most
72 cases. This timeout defaults to 3600E<nbsp>seconds.
73
74 =item B<-p> I<file>
75
76 Sets the name and location of the PID-file. If not specified, the default,
77 C<I<$localststedir>/run/rrdcached.pid> will be used.
78
79 =item B<-j> I<dir>
80
81 Write updates to a journal in I<dir>.  In the event of a program or system
82 crash, this will allow the daemon to write any updates that were pending
83 at the time of the crash.
84
85 On startup, the daemon will check for journal files in this directory.  If
86 found, all updates therein will be read into memory before the daemon
87 starts accepting new connections.
88
89 The journal will be rotated with the same frequency as the flush timer
90 given by B<-f>.  On clean shutdown, the journal files are removed.
91
92 =item B<-b> I<dir>
93
94 The daemon will change into a specific directory at startup. All files passed
95 to the daemon, that are specified by a B<relative> path, will be interpreted
96 to be relative to this directory. If not given the default, C</tmp>, will be
97 used.
98
99   +------------------------+------------------------+
100   ! Command line           ! File updated           !
101   +------------------------+------------------------+
102   ! foo.rrd                ! /tmp/foo.rrd           !
103   ! foo/bar.rrd            ! /tmp/foo/bar.rrd       !
104   ! /var/lib/rrd/foo.rrd   ! /var/lib/rrd/foo.rrd   !
105   +------------------------+------------------------+
106   Paths given on the command  line and paths actually
107   updated by the daemon,  assuming the base directory
108   "/tmp".
109
110 =back
111
112 =head1 EFFECTED RRDTOOL COMMANDS
113
114 The following commands may be made aware of the B<rrdcached> using the command
115 line argument B<--daemon> or the environment variable B<RRDCACHED_ADDRESS>:
116
117 =over 4
118
119 =item B<dump>
120
121 =item B<fetch>
122
123 =item B<flush>
124
125 =item B<graph>
126
127 =item B<graphv>
128
129 =item B<info>
130
131 =item B<last>
132
133 =item B<lastupdate>
134
135 =item B<update>
136
137 =item B<xport>
138
139 =back
140
141 The B<update> command can send values to the daemon instead of writing them to
142 the disk itself. All other commands can send a B<FLUSH> command (see below) to
143 the daemon before accessing the files, so they work with up-to-date data even
144 if the cache timeout is large.
145
146 =head1 ERROR REPORTING
147
148 The daemon reports errors in one of two ways: During startup, error messages
149 are printed to C<STDERR>. One of the steps when starting up is to fork to the
150 background and closing C<STDERR> - after this writing directly to the user is
151 no longer possible. Once this has happened, the daemon will send log messages
152 to the system logging daemon using L<syslog(3)>. The facility used it
153 C<LOG_DAEMON>.
154
155 =head1 HOW IT WORKS
156
157 When receiving an update, B<rrdcached> does not write to disk but looks for an
158 entry for that file in its internal tree. If not found, an entry is created
159 including the current time (called "First" in the diagram below). This time is
160 B<not> the time specified on the command line but the time the operating system
161 considers to be "now". The value and time of the value (called "Time" in the
162 diagram below) are appended to the tree node.
163
164 When appending a value to a tree node, it is checked whether it's time to write
165 the values to disk. Values are written to disk if
166 S<C<now() - First E<gt>= timeout>>, where C<timeout> is the timeout specified
167 using the B<-w> option, see L<OPTIONS>. If the values are "old enough" they
168 will be enqueued in the "update queue", i.E<nbsp>e. they will be appended to
169 the linked list shown below.  Because the tree nodes and the elements of the
170 linked list are the same data structures in memory, any update to a file that
171 has already been enqueued will be written with the next write to the RRD file,
172 too.
173
174 A separate "update thread" constantly dequeues the first element in the update
175 queue and writes all its values to the appropriate file. So as long as the
176 update queue is not empty files are written at the highest possible rate.
177
178 Since the timeout of files is checked only when new values are added to the
179 file, "dead" files, i.E<nbsp>e. files that are not updated anymore, would never
180 be written to disk. Therefore, every now and then, controlled by the B<-f>
181 option, the entire tree is walked and all "old" values are enqueued. Since this
182 only affects "dead" files and walking the tree is relatively expensive, you
183 should set the "flush interval" to a reasonably high value. The default is
184 3600E<nbsp>seconds (one hour).
185
186 The downside of caching values is that they won't show up in graphs generated
187 from the RRDE<nbsp>files. To get around this, the daemon provides the "flush
188 command" to flush specific files. This means that the file is inserted at the
189 B<head> of the update queue or moved there if it is already enqueued. The flush
190 command will return only after the file's pending updates have been written
191 to disk.
192
193  +------+   +------+                               +------+
194  ! head !   ! root !                               ! tail !
195  +---+--+   +---+--+                               +---+--+
196      !         /\                                      !
197      !        /  \                                     !
198      !       /\  /\                                    !
199      !      /\/\ \ `----------------- ... --------,    !
200      V     /      `-------,                       !    V
201  +---+----+---+    +------+-----+             +---+----+---+
202  ! File:  foo !    ! File:  bar !             ! File:  qux !
203  ! First: 101 !    ! First: 119 !             ! First: 180 !
204  ! Next:   ---+--->! Next:   ---+---> ... --->! Next:   -  !
205  +============+    +============+             +============+
206  ! Time:  100 !    ! Time:  120 !             ! Time:  180 !
207  ! Value:  10 !    ! Value: 0.1 !             ! Value: 2,2 !
208  +------------+    +------------+             +------------+
209  ! Time:  110 !    ! Time:  130 !             ! Time:  190 !
210  ! Value:  26 !    ! Value: 0.1 !             ! Value: 7,3 !
211  +------------+    +------------+             +------------+
212  :            :    :            :             :            :
213  +------------+    +------------+             +------------+
214  ! Time:  230 !    ! Time:  250 !             ! Time:  310 !
215  ! Value:  42 !    ! Value: 0.2 !             ! Value: 1,2 !
216  +------------+    +------------+             +------------+
217
218 The above diagram demonstrates:
219
220 =over
221
222 =item *
223
224 Files/values are stored in a (balanced) tree.
225
226 =item *
227
228 Tree nodes and entries in the update queue are the same data structure.
229
230 =item *
231
232 The local time ("First") and the time specified in updates ("Time") may differ.  
233
234 =item *
235
236 Timed out values are inserted at the "tail".
237
238 =item *
239
240 Explicitly flushed values are inserted at the "head".
241
242 =item *
243
244 ASCII art rocks.
245
246 =back
247
248 =head1 SECURITY CONSIDERATIONS
249
250 This daemon is meant to improve IOE<nbsp>performance for setups with thousands
251 of RRDE<nbsp>file to be updated. So security measures built into the daemon can
252 be summarized easily: B<There is no security built in!>
253
254 There is no authentication and authorization, so B<you> will have to take care
255 that only authorized clients can talk to the daemon. Since we assume that graph
256 collection is done on a dedicated machine, i.E<nbsp>e. the box doesn't do
257 anything else and especially does not have any interactive logins other than
258 root, a UNIX domain socket should take care of that.
259
260 If you (want to) use the network capability, i.E<nbsp>e. let the daemon bind to
261 an IPv4 or IPv6 socket, it is B<your> job to install a packet filter or similar
262 mechanism to prevent unauthorized connections. Unless you have a dedicated VLAN
263 or VPN for this, using the network option is probably a bad idea!
264
265 The daemon will blindly write to any file it gets told, so you really should
266 create a separate user just for this daemon. Also it does not do any sanity
267 checks, so if it gets told to write values for a time far in the future, your
268 files will be messed up good!
269
270 You have been warned.
271
272 =head1 PROTOCOL
273
274 The daemon communicates with clients using a line based ASCII protocol which is
275 easy to read and easy to type. This makes it easy for scripts to implement the
276 protocol and possible for users to use L<telnet> to connect to the daemon
277 and test stuff "by hand".
278
279 The protocol is line based, this means that each record consists of one or more
280 lines. A line is terminated by the line feed character C<0x0A>, commonly
281 written as C<\n>. In the examples below, this character will be written as
282 C<E<lt>LFE<gt>> ("line feed").
283
284 After the connection has been established, the client is expected to send a
285 "command". A command consists of the command keyword, possibly some arguments,
286 and a terminating newline character. For a list of commands, see
287 L<Valid Commands> below.
288
289 Example:
290
291   FLUSH /tmp/foo.rrd<LF>
292
293 The daemon answers with a line consisting of a status code and a short status
294 message, separated by one or more space characters. A negative status code
295 signals an error, a positive status code or zero signal success. If the status
296 code is greater than zero, it indicates the number of lines that follow the
297 status line.
298
299 Examples:
300
301  0 Success<LF>
302
303  2 Two lines follow<LF>
304  This is the first line<LF>
305  And this is the second line<LF>
306
307 =head2 Valid Commands
308
309 The following commands are understood by the daemon:
310
311 =over 4
312
313 =item B<FLUSH> I<filename>
314
315 Causes the daemon to put I<filename> to the B<head> of the update queue
316 (possibly moving it there if the node is already enqueued). The answer will be
317 sent B<after> the node has been dequeued.
318
319 =item B<FLUSHALL>
320
321 Causes the daemon to start flushing ALL pending values to disk.  This
322 returns immediately, even though the writes may take a long time.
323
324 =item B<HELP> [I<command>]
325
326 Returns a short usage message. If no command is given, or I<command> is
327 B<HELP>, a list of commands supported by the daemon is returned. Otherwise a
328 short description, possibly containing a pointer to a manual page, is returned.
329 Obviously, this is meant for interactive usage and the format in which the
330 commands and usage summaries are returned is not well defined.
331
332 =item B<STATS>
333
334 Returns a list of metrics which can be used to measure the daemons performance
335 and check its status. For a description of the values returned, see
336 L<Performance Values> below.
337
338 The format in which the values are returned is similar to many other line based
339 protocols: Each value is printed on a separate line, each consisting of the
340 name of the value, a colon, one or more spaces and the actual value.
341
342 Example:
343
344  9 Statistics follow
345  QueueLength: 0
346  UpdatesReceived: 30
347  FlushesReceived: 2
348  UpdatesWritten: 13
349  DataSetsWritten: 390
350  TreeNodesNumber: 13
351  TreeDepth: 4
352  JournalBytes: 190
353  JournalRotate: 0
354
355 =item B<UPDATE> I<filename> I<values> [I<values> ...]
356
357 Adds more data to a filename. This is B<the> operation the daemon was designed
358 for, so describing the mechanism again is unnecessary. Read L<HOW IT WORKS>
359 above for a detailed explanation.
360
361 =item B<WROTE> I<filename>
362
363 This command is written to the journal after a file is successfully
364 written out to disk.  It is used during journal replay to determine which
365 updates have already been applied.  It is I<only> valid in the journal; it
366 is not accepted from the other command channels.
367
368 =back
369
370 =head2 Performance Values
371
372 The following counters are returned by the B<STATS> command:
373
374 =over 4
375
376 =item B<QueueLength> I<(unsigned 64bit integer)>
377
378 Number of nodes currently enqueued in the update queue.
379
380 =item B<UpdatesReceived> I<(unsigned 64bit integer)>
381
382 Number of UPDATE commands received.
383
384 =item B<FlushesReceived> I<(unsigned 64bit integer)>
385
386 Number of FLUSH commands received.
387
388 =item B<UpdatesWritten> I<(unsigned 64bit integer)>
389
390 Total number of updates, i.E<nbsp>e. calls to C<rrd_update_r>, since the
391 daemon was started.
392
393 =item B<DataSetsWritten> I<(unsigned 64bit integer)>
394
395 Total number of "data sets" written to disk since the daemon was started. A
396 data set is one or more values passed to the B<UPDATE> command. For example:
397 C<N:123:456> is one data set with two values. The term "data set" is used to
398 prevent confusion whether individual values or groups of values are counted.
399
400 =item B<TreeNodesNumber> I<(unsigned 64bit integer)>
401
402 Number of nodes in the cache.
403
404 =item B<TreeDepth> I<(unsigned 64bit integer)>
405
406 Depth of the tree used for fast key lookup.
407
408 =item B<JournalBytes> I<(unsigned 64bit integer)>
409
410 Total number of bytes written to the journal since startup.
411
412 =item B<JournalRotate> I<(unsigned 64bit integer)>
413
414 Number of times the journal has been rotated since startup.
415
416 =back
417
418 =head1 SIGNALS
419
420 =over 4
421
422 =item SIGINT and SIGTERM
423
424 The daemon exits normally on receipt of either of these signals.
425
426 =back
427
428 =head1 BUGS
429
430 No known bugs at the moment.
431
432 =head1 SEE ALSO
433
434 L<rrdtool>, L<rrdgraph>
435
436 =head1 AUTHOR
437
438 B<rrdcached> and this manual page have been written by Florian Forster
439 E<lt>octoE<nbsp>atE<nbsp>verplant.orgE<gt>.
440
441 =head1 CONTRIBUTORS
442
443 kevin brintnall E<lt>kbrint@rufus.netE<gt>
444
445 =cut
446