rrdcached(1): Added the `SECURITY CONSIDERATIONS' and `HOW IT WORKS' sections.
[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 BUGS
196
197 =over 4
198
199 =item
200
201 Tree nodes are never deleted.
202
203 =back
204
205 =head1 SEE ALSO
206
207 L<rrdtool(1)>, L<rrdgraph(1)>
208
209 =head1 AUHOR
210
211 B<rrdcached> and this manual page have been written by Florian Forster
212 E<lt>octoE<nbsp>atE<nbsp>verplant.orgE<gt>.