Code

Merge branch 'collectd-5.4'
[collectd.git] / src / collectd-exec.pod
1 =encoding UTF-8
3 =head1 NAME
5 collectd-exec - Documentation of collectd's C<exec plugin>
7 =head1 SYNOPSIS
9   # See collectd.conf(5)
10   LoadPlugin exec
11   # ...
12   <Plugin exec>
13     Exec "myuser:mygroup" "myprog"
14     Exec "otheruser" "/path/to/another/binary" "arg0" "arg1"
15     NotificationExec "user" "/usr/lib/collectd/exec/handle_notification"
16   </Plugin>
18 =head1 DESCRIPTION
20 The C<exec plugin> forks of an executable either to receive values or to
21 dispatch notifications to the outside world. The syntax of the configuration is
22 explained in L<collectd.conf(5)> but summarized in the above synopsis.
24 If you want/need better performance or more functionality you should take a
25 long look at the C<perl plugin>, L<collectd-perl(5)>.
27 =head1 EXECUTABLE TYPES
29 There are currently two types of executables that can be executed by the
30 C<exec plugin>:
32 =over 4
34 =item C<Exec>
36 These programs are forked and values that it writes to C<STDOUT> are read back.
37 The executable is forked in a fashion similar to L<init>: It is forked once and
38 not again until it exits. If it exited, it will be forked again after at most
39 I<Interval> seconds. It is perfectly legal for the executable to run for a long
40 time and continuously write values to C<STDOUT>.
42 See L<EXEC DATA FORMAT> below for a description of the output format expected
43 from these programs.
45 B<Warning:> If the executable only writes one value and then exits I will be
46 executed every I<Interval> seconds. If I<Interval> is short (the default is 10
47 seconds) this may result in serious system load.
49 =item C<NotificationExec>
51 The program is forked once for each notification that is handled by the daemon.
52 The notification is passed to the program on C<STDIN> in a fashion similar to
53 HTTP-headers. In contrast to programs specified with C<Exec> the execution of
54 this program is not serialized, so that several instances of this program may
55 run at once if multiple notifications are received.
57 See L<NOTIFICATION DATA FORMAT> below for a description of the data passed to
58 these programs.
60 =back
62 =head1 EXEC DATA FORMAT
64 The forked executable is expected to print values to C<STDOUT>. The expected
65 format is as follows:
67 =over 4
69 =item Comments
71 Each line beginning with a C<#> (hash mark) is ignored.
73 =item B<PUTVAL> I<Identifier> [I<OptionList>] I<Valuelist>
75 Submits one or more values (identified by I<Identifier>, see below) to the
76 daemon which will dispatch it to all it's write-plugins.
78 An I<Identifier> is of the form
79 C<I<host>B</>I<plugin>B<->I<instance>B</>I<type>B<->I<instance>> with both
80 I<instance>-parts being optional. If they're omitted the hyphen must be
81 omitted, too. I<plugin> and each I<instance>-part may be chosen freely as long
82 as the tuple (plugin, plugin instance, type instance) uniquely identifies the
83 plugin within collectd. I<type> identifies the type and number of values
84 (i.E<nbsp>e. data-set) passed to collectd. A large list of predefined
85 data-sets is available in the B<types.db> file. See L<types.db(5)> for a
86 description of the format of this file.
88 The I<OptionList> is an optional list of I<Options>, where each option is a
89 key-value-pair. A list of currently understood options can be found below, all
90 other options will be ignored. Values that contain spaces must be quoted with
91 double quotes.
93 I<Valuelist> is a colon-separated list of the time and the values, each either
94 an integer if the data-source is a counter, or a double if the data-source is
95 of type "gauge". You can submit an undefined gauge-value by using B<U>. When
96 submitting B<U> to a counter the behavior is undefined. The time is given as
97 epoch (i.E<nbsp>e. standard UNIX time).
99 You can mix options and values, but the order is important: Options only
100 effect following values, so specifying an option as last field is allowed, but
101 useless. Also, an option applies to B<all> following values, so you don't need
102 to re-set an option over and over again.
104 The currently defined B<Options> are:
106 =over 4
108 =item B<interval=>I<seconds>
110 Gives the interval in which the data identified by I<Identifier> is being
111 collected.
113 =back
115 Please note that this is the same format as used in the B<unixsock plugin>, see
116 L<collectd-unixsock(5)>. There's also a bit more information on identifiers in
117 case you're confused.
119 Since examples usually let one understand a lot better, here are some:
121   PUTVAL leeloo/cpu-0/cpu-idle N:2299366
122   PUTVAL alice/interface/if_octets-eth0 interval=10 1180647081:421465:479194
124 =item B<PUTNOTIF> [I<OptionList>] B<message=>I<Message>
126 Submits a notification to the daemon which will then dispatch it to all plugins
127 which have registered for receiving notifications. 
129 The B<PUTNOTIF> if followed by a list of options which further describe the
130 notification. The B<message> option is special in that it will consume the rest
131 of the line as its value. The B<message>, B<severity>, and B<time> options are
132 mandatory.
134 Valid options are:
136 =over 4
138 =item B<message=>I<Message> (B<REQUIRED>)
140 Sets the message of the notification. This is the message that will be made
141 accessible to the user, so it should contain some useful information. As with
142 all options: If the message includes spaces, it must be quoted with double
143 quotes. This option is mandatory.
145 =item B<severity=failure>|B<warning>|B<okay> (B<REQUIRED>)
147 Sets the severity of the notification. This option is mandatory.
149 =item B<time=>I<Time> (B<REQUIRED>)
151 Sets the time of the notification. The time is given as "epoch", i.E<nbsp>e. as
152 seconds since January 1st, 1970, 00:00:00. This option is mandatory.
154 =item B<host=>I<Hostname>
156 =item B<plugin=>I<Plugin>
158 =item B<plugin_instance=>I<Plugin-Instance>
160 =item B<type=>I<Type>
162 =item B<type_instance=>I<Type-Instance>
164 These "associative" options establish a relation between this notification and
165 collected performance data. This connection is purely informal, i.E<nbsp>e. the
166 daemon itself doesn't do anything with this information. However, websites or
167 GUIs may use this information to place notifications near the affected graph or
168 table. All the options are optional, but B<plugin_instance> without B<plugin>
169 or B<type_instance> without B<type> doesn't make much sense and should be
170 avoided.
172 =item B<type:key=>I<value>
174 Sets user defined meta information. The B<type> key is a single character
175 defining the type of the meta information.
177 The current supported types are:
179 =over 8
181 =item B<s> A string passed as-is.
183 =back
185 =back
187 =back
189 Please note that this is the same format as used in the B<unixsock plugin>, see
190 L<collectd-unixsock(5)>.
192 When collectd exits it sends a B<SIGTERM> to all still running
193 child-processes upon which they have to quit.
195 =head1 NOTIFICATION DATA FORMAT
197 The notification executables receive values rather than providing them. In
198 fact, after the program is started C<STDOUT> is connected to C</dev/null>.
200 The data is passed to the executables over C<STDIN> in a format very similar to
201 HTTP: At first there is a "header" with one line per field. Every line consists
202 of a field name, ended by a colon, and the associated value until end-of-line.
203 The "header" is ended by two newlines immediately following another,
204 i.E<nbsp>e. an empty line. The rest, basically the "body", is the message of
205 the notification.
207 The following is an example notification passed to a program:
209   Severity: FAILURE
210   Time: 1200928930
211   Host: myhost.mydomain.org
212   \n
213   This is a test notification to demonstrate the format
215 The following header files are currently used. Please note, however, that you
216 should ignore unknown header files to be as forward-compatible as possible.
218 =over 4
220 =item B<Severity>
222 Severity of the notification. May either be B<FAILURE>, B<WARNING>, or B<OKAY>.
224 =item B<Time>
226 The time in epoch, i.E<nbsp>e. as seconds since 1970-01-01 00:00:00 UTC.
228 =item B<Host>
230 =item B<Plugin>
232 =item B<PluginInstance>
234 =item B<Type>
236 =item B<TypeInstance>
238 Identification of the performance data this notification is associated with.
239 All of these fields are optional because notifications do not B<need> to be
240 associated with a certain value.
242 =back
244 =head1 ENVIRONMENT
246 The following environment variables are set by the plugin before calling
247 I<exec>:
249 =over 4
251 =item COLLECTD_INTERVAL
253 Value of the global interval setting.
255 =item COLLECTD_HOSTNAME
257 Hostname used by I<collectd> to dispatch local values.
259 =back
261 =head1 USING NAGIOS PLUGINS
263 Though the interface is far from perfect, there are tons of plugins for Nagios.
264 You can use these plugins with collectd by using a simple transition layer,
265 C<exec-nagios.px>, which is shipped with the collectd distribution in the
266 C<contrib/> directory. It is a simple Perl script that comes with embedded
267 documentation. To see it, run the following command:
269   perldoc exec-nagios.px
271 This script expects a configuration file, C<exec-nagios.conf>. You can find an
272 example in the C<contrib/> directory, too.
274 Even a simple mechanism to submit "performance data" to collectd is
275 implemented. If you need a more sophisticated setup, please rewrite the plugin
276 to make use of collectd's more powerful interface.
278 =head1 CAVEATS
280 =over 4
282 =item
284 The user, the binary is executed as, may not have root privileges, i.E<nbsp>e.
285 must have an UID that is non-zero. This is for your own good.
287 =item
289 Early versions of the plugin did not use a command but treated all lines as if
290 they were arguments to the I<PUTVAL> command. When the I<PUTNOTIF> command was
291 implemented, this behavior was kept for lines which start with an unknown
292 command for backwards compatibility. This compatibility code has been removed
293 in I<collectdE<nbsp>5>.
295 =back
297 =head1 SEE ALSO
299 L<collectd(1)>,
300 L<collectd.conf(5)>,
301 L<collectd-perl(5)>,
302 L<collectd-unixsock(5)>,
303 L<fork(2)>, L<exec(3)>
305 =head1 AUTHOR
307 Florian Forster E<lt>octo@collectd.orgE<gt>
309 =cut