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