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