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