Code

Imported Upstream version 5.5.0
[pkg-collectd.git] / src / collectd-perl.5
1 .\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28)
2 .\"
3 .\" Standard preamble:
4 .\" ========================================================================
5 .de Sp \" Vertical space (when we can't use .PP)
6 .if t .sp .5v
7 .if n .sp
8 ..
9 .de Vb \" Begin verbatim text
10 .ft CW
11 .nf
12 .ne \\$1
13 ..
14 .de Ve \" End verbatim text
15 .ft R
16 .fi
17 ..
18 .\" Set up some character translations and predefined strings.  \*(-- will
19 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
20 .\" double quote, and \*(R" will give a right double quote.  \*(C+ will
21 .\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
22 .\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
23 .\" nothing in troff, for use with C<>.
24 .tr \(*W-
25 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
26 .ie n \{\
27 .    ds -- \(*W-
28 .    ds PI pi
29 .    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
30 .    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
31 .    ds L" ""
32 .    ds R" ""
33 .    ds C` ""
34 .    ds C' ""
35 'br\}
36 .el\{\
37 .    ds -- \|\(em\|
38 .    ds PI \(*p
39 .    ds L" ``
40 .    ds R" ''
41 .    ds C`
42 .    ds C'
43 'br\}
44 .\"
45 .\" Escape single quotes in literal strings from groff's Unicode transform.
46 .ie \n(.g .ds Aq \(aq
47 .el       .ds Aq '
48 .\"
49 .\" If the F register is turned on, we'll generate index entries on stderr for
50 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
51 .\" entries marked with X<> in POD.  Of course, you'll have to process the
52 .\" output yourself in some meaningful fashion.
53 .\"
54 .\" Avoid warning from groff about undefined register 'F'.
55 .de IX
56 ..
57 .nr rF 0
58 .if \n(.g .if rF .nr rF 1
59 .if (\n(rF:(\n(.g==0)) \{
60 .    if \nF \{
61 .        de IX
62 .        tm Index:\\$1\t\\n%\t"\\$2"
63 ..
64 .        if !\nF==2 \{
65 .            nr % 0
66 .            nr F 2
67 .        \}
68 .    \}
69 .\}
70 .rr rF
71 .\"
72 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
73 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
74 .    \" fudge factors for nroff and troff
75 .if n \{\
76 .    ds #H 0
77 .    ds #V .8m
78 .    ds #F .3m
79 .    ds #[ \f1
80 .    ds #] \fP
81 .\}
82 .if t \{\
83 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
84 .    ds #V .6m
85 .    ds #F 0
86 .    ds #[ \&
87 .    ds #] \&
88 .\}
89 .    \" simple accents for nroff and troff
90 .if n \{\
91 .    ds ' \&
92 .    ds ` \&
93 .    ds ^ \&
94 .    ds , \&
95 .    ds ~ ~
96 .    ds /
97 .\}
98 .if t \{\
99 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
100 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
101 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
102 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
103 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
104 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
105 .\}
106 .    \" troff and (daisy-wheel) nroff accents
107 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
108 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
109 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
110 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
111 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
112 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
113 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
114 .ds ae a\h'-(\w'a'u*4/10)'e
115 .ds Ae A\h'-(\w'A'u*4/10)'E
116 .    \" corrections for vroff
117 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
118 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
119 .    \" for low resolution devices (crt and lpr)
120 .if \n(.H>23 .if \n(.V>19 \
121 \{\
122 .    ds : e
123 .    ds 8 ss
124 .    ds o a
125 .    ds d- d\h'-1'\(ga
126 .    ds D- D\h'-1'\(hy
127 .    ds th \o'bp'
128 .    ds Th \o'LP'
129 .    ds ae ae
130 .    ds Ae AE
131 .\}
132 .rm #[ #] #H #V #F C
133 .\" ========================================================================
134 .\"
135 .IX Title "COLLECTD-PERL 5"
136 .TH COLLECTD-PERL 5 "2015-05-20" "5.4.2.911.g0c88d3b" "collectd"
137 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
138 .\" way too many mistakes in technical documents.
139 .if n .ad l
140 .nh
141 .SH "NAME"
142 collectd\-perl \- Documentation of collectd's "perl plugin"
143 .SH "SYNOPSIS"
144 .IX Header "SYNOPSIS"
145 .Vb 7
146 \&  LoadPlugin perl
147 \&  # ...
148 \&  <Plugin perl>
149 \&    IncludeDir "/path/to/perl/plugins"
150 \&    BaseName "Collectd::Plugins"
151 \&    EnableDebugger ""
152 \&    LoadPlugin "FooBar"
153 \&
154 \&    <Plugin FooBar>
155 \&      Foo "Bar"
156 \&    </Plugin>
157 \&  </Plugin>
158 .Ve
159 .SH "DESCRIPTION"
160 .IX Header "DESCRIPTION"
161 The \f(CW\*(C`perl plugin\*(C'\fR embeds a Perl-interpreter into collectd and provides an
162 interface to collectd's plugin system. This makes it possible to write plugins
163 for collectd in Perl. This is a lot more efficient than executing a
164 Perl-script every time you want to read a value with the \f(CW\*(C`exec plugin\*(C'\fR (see
165 \&\fIcollectd\-exec\fR\|(5)) and provides a lot more functionality, too.
166 .SH "CONFIGURATION"
167 .IX Header "CONFIGURATION"
168 .IP "\fBLoadPlugin\fR \fIPlugin\fR" 4
169 .IX Item "LoadPlugin Plugin"
170 Loads the Perl plugin \fIPlugin\fR. This does basically the same as \fBuse\fR would
171 do in a Perl program. As a side effect, the first occurrence of this option
172 causes the Perl-interpreter to be initialized.
173 .IP "\fBBaseName\fR \fIName\fR" 4
174 .IX Item "BaseName Name"
175 Prepends \fIName\fR\fB::\fR to all plugin names loaded after this option. This is
176 provided for convenience to keep plugin names short. All Perl-based plugins
177 provided with the \fIcollectd\fR distributions reside in the \f(CW\*(C`Collectd::Plugins\*(C'\fR
178 namespace.
179 .IP "<\fBPlugin\fR \fIName\fR> block" 4
180 .IX Item "<Plugin Name> block"
181 This block may be used to pass on configuration settings to a Perl plugin. The
182 configuration is converted into a config-item data type which is passed to the
183 registered configuration callback. See below for details about the config-item
184 data type and how to register callbacks.
185 .Sp
186 The \fIname\fR identifies the callback. It is used literally and independent of
187 the \fBBaseName\fR setting.
188 .IP "\fBEnableDebugger\fR \fIPackage\fR[=\fIoption\fR,...]" 4
189 .IX Item "EnableDebugger Package[=option,...]"
190 Run collectd under the control of the Perl source debugger. If \fIPackage\fR is
191 not the empty string, control is passed to the debugging, profiling, or
192 tracing module installed as Devel::\fIPackage\fR. A comma-separated list of
193 options may be specified after the \*(L"=\*(R" character. Please note that you may not
194 leave out the \fIPackage\fR option even if you specify \fB""\fR. This is the same as
195 using the \fB\-d:Package\fR command line option.
196 .Sp
197 See perldebug for detailed documentation about debugging Perl.
198 .Sp
199 This option does not prevent collectd from daemonizing, so you should start
200 collectd with the \fB\-f\fR command line option. Else you will not be able to use
201 the command line driven interface of the debugger.
202 .IP "\fBIncludeDir\fR \fIDir\fR" 4
203 .IX Item "IncludeDir Dir"
204 Adds \fIDir\fR to the \fB\f(CB@INC\fB\fR array. This is the same as using the \fB\-IDir\fR
205 command line option or \fBuse lib Dir\fR in the source code. Please note that it
206 only has effect on plugins loaded after this option.
207 .SH "WRITING YOUR OWN PLUGINS"
208 .IX Header "WRITING YOUR OWN PLUGINS"
209 Writing your own plugins is quite simple. collectd manages plugins by means of
210 \&\fBdispatch functions\fR which call the appropriate \fBcallback functions\fR
211 registered by the plugins. Any plugin basically consists of the implementation
212 of these callback functions and initializing code which registers the
213 functions with collectd. See the section \*(L"\s-1EXAMPLES\*(R"\s0 below for a really basic
214 example. The following types of \fBcallback functions\fR are known to collectd
215 (all of them are optional):
216 .IP "configuration functions" 4
217 .IX Item "configuration functions"
218 This type of functions is called during configuration if an appropriate
219 \&\fBPlugin\fR block has been encountered. It is called once for each \fBPlugin\fR
220 block which matches the name of the callback as provided with the
221 \&\fBplugin_register\fR method \- see below.
222 .IP "init functions" 4
223 .IX Item "init functions"
224 This type of functions is called once after loading the module and before any
225 calls to the read and write functions. It should be used to initialize the
226 internal state of the plugin (e.\ g. open sockets, ...). If the return
227 value evaluates to \fBfalse\fR, the plugin will be disabled.
228 .IP "read functions" 4
229 .IX Item "read functions"
230 This type of function is used to collect the actual data. It is called once
231 per interval (see the \fBInterval\fR configuration option of collectd). Usually
232 it will call \fBplugin_dispatch_values\fR to dispatch the values to collectd
233 which will pass them on to all registered \fBwrite functions\fR. If the return
234 value evaluates to \fBfalse\fR the plugin will be skipped for an increasing
235 amount of time until it returns \fBtrue\fR again.
236 .IP "write functions" 4
237 .IX Item "write functions"
238 This type of function is used to write the dispatched values. It is called
239 once for each call to \fBplugin_dispatch_values\fR.
240 .IP "flush functions" 4
241 .IX Item "flush functions"
242 This type of function is used to flush internal caches of plugins. It is
243 usually triggered by the user only. Any plugin which caches data before
244 writing it to disk should provide this kind of callback function.
245 .IP "log functions" 4
246 .IX Item "log functions"
247 This type of function is used to pass messages of plugins or the daemon itself
248 to the user.
249 .IP "notification function" 4
250 .IX Item "notification function"
251 This type of function is used to act upon notifications. In general, a
252 notification is a status message that may be associated with a data instance.
253 Usually, a notification is generated by the daemon if a configured threshold
254 has been exceeded (see the section \*(L"\s-1THRESHOLD CONFIGURATION\*(R"\s0 in
255 \&\fIcollectd.conf\fR\|(5) for more details), but any plugin may dispatch
256 notifications as well.
257 .IP "shutdown functions" 4
258 .IX Item "shutdown functions"
259 This type of function is called once before the daemon shuts down. It should
260 be used to clean up the plugin (e.g. close sockets, ...).
261 .PP
262 Any function (except log functions) may set the \fB$@\fR variable to describe
263 errors in more detail. The message will be passed on to the user using
264 collectd's logging mechanism.
265 .PP
266 See the documentation of the \fBplugin_register\fR method in the section
267 \&\*(L"\s-1METHODS\*(R"\s0 below for the number and types of arguments passed to each
268 \&\fBcallback function\fR. This section also explains how to register \fBcallback
269 functions\fR with collectd.
270 .PP
271 To enable a plugin, copy it to a place where Perl can find it (i.\ e. a
272 directory listed in the \fB\f(CB@INC\fB\fR array) just as any other Perl plugin and add
273 an appropriate \fBLoadPlugin\fR option to the configuration file. After
274 restarting collectd you're done.
275 .SH "DATA TYPES"
276 .IX Header "DATA TYPES"
277 The following complex types are used to pass values between the Perl plugin
278 and collectd:
279 .IP "Config-Item" 4
280 .IX Item "Config-Item"
281 A config-item is one structure which keeps the information provided in the
282 configuration file. The array of children keeps one entry for each
283 configuration option. Each such entry is another config-item structure, which
284 may nest further if nested blocks are used.
285 .Sp
286 .Vb 5
287 \&  {
288 \&    key      => key,
289 \&    values   => [ val1, val2, ... ],
290 \&    children => [ { ... }, { ... }, ... ]
291 \&  }
292 .Ve
293 .IP "Data-Set" 4
294 .IX Item "Data-Set"
295 A data-set is a list of one or more data-sources. Each data-source defines a
296 name, type, min\- and max-value and the data-set wraps them up into one
297 structure. The general layout looks like this:
298 .Sp
299 .Vb 6
300 \&  [{
301 \&    name => \*(Aqdata_source_name\*(Aq,
302 \&    type => DS_TYPE_COUNTER || DS_TYPE_GAUGE || DS_TYPE_DERIVE || DS_TYPE_ABSOLUTE,
303 \&    min  => value || undef,
304 \&    max  => value || undef
305 \&  }, ...]
306 .Ve
307 .IP "Value-List" 4
308 .IX Item "Value-List"
309 A value-list is one structure which features an array of values and fields to
310 identify the values, i.\ e. time and host, plugin name and
311 plugin-instance as well as a type and type-instance. Since the \*(L"type\*(R" is not
312 included in the value-list but is passed as an extra argument, the general
313 layout looks like this:
314 .Sp
315 .Vb 10
316 \&  {
317 \&    values => [123, 0.5],
318 \&    time   => time (),
319 \&    interval => plugin_get_interval (),
320 \&    host   => $hostname_g,
321 \&    plugin => \*(Aqmyplugin\*(Aq,
322 \&    type   => \*(Aqmyplugin\*(Aq,
323 \&    plugin_instance => \*(Aq\*(Aq,
324 \&    type_instance   => \*(Aq\*(Aq
325 \&  }
326 .Ve
327 .IP "Notification" 4
328 .IX Item "Notification"
329 A notification is one structure defining the severity, time and message of the
330 status message as well as an identification of a data instance. Also, it
331 includes an optional list of user-defined meta information represented as
332 (name, value) pairs:
333 .Sp
334 .Vb 11
335 \&  {
336 \&    severity => NOTIF_FAILURE || NOTIF_WARNING || NOTIF_OKAY,
337 \&    time     => time (),
338 \&    message  => \*(Aqstatus message\*(Aq,
339 \&    host     => $hostname_g,
340 \&    plugin   => \*(Aqmyplugin\*(Aq,
341 \&    type     => \*(Aqmytype\*(Aq,
342 \&    plugin_instance => \*(Aq\*(Aq,
343 \&    type_instance   => \*(Aq\*(Aq,
344 \&    meta     => [ { name => <name>, value => <value> }, ... ]
345 \&  }
346 .Ve
347 .IP "Match-Proc" 4
348 .IX Item "Match-Proc"
349 A match-proc is one structure storing the callbacks of a \*(L"match\*(R" of the filter
350 chain infrastructure. The general layout looks like this:
351 .Sp
352 .Vb 5
353 \&  {
354 \&    create  => \*(Aqmy_create\*(Aq,
355 \&    destroy => \*(Aqmy_destroy\*(Aq,
356 \&    match   => \*(Aqmy_match\*(Aq
357 \&  }
358 .Ve
359 .IP "Target-Proc" 4
360 .IX Item "Target-Proc"
361 A target-proc is one structure storing the callbacks of a \*(L"target\*(R" of the
362 filter chain infrastructure. The general layout looks like this:
363 .Sp
364 .Vb 5
365 \&  {
366 \&    create  => \*(Aqmy_create\*(Aq,
367 \&    destroy => \*(Aqmy_destroy\*(Aq,
368 \&    invoke  => \*(Aqmy_invoke\*(Aq
369 \&  }
370 .Ve
371 .SH "METHODS"
372 .IX Header "METHODS"
373 The following functions provide the C\-interface to Perl-modules. They are
374 exported by the \*(L":plugin\*(R" export tag (see the section \*(L"\s-1EXPORTS\*(R"\s0 below).
375 .IP "\fBplugin_register\fR (\fItype\fR, \fIname\fR, \fIdata\fR)" 4
376 .IX Item "plugin_register (type, name, data)"
377 Registers a callback-function or data-set.
378 .Sp
379 \&\fItype\fR can be one of:
380 .RS 4
381 .IP "\s-1TYPE_CONFIG\s0" 4
382 .IX Item "TYPE_CONFIG"
383 .PD 0
384 .IP "\s-1TYPE_INIT\s0" 4
385 .IX Item "TYPE_INIT"
386 .IP "\s-1TYPE_READ\s0" 4
387 .IX Item "TYPE_READ"
388 .IP "\s-1TYPE_WRITE\s0" 4
389 .IX Item "TYPE_WRITE"
390 .IP "\s-1TYPE_FLUSH\s0" 4
391 .IX Item "TYPE_FLUSH"
392 .IP "\s-1TYPE_LOG\s0" 4
393 .IX Item "TYPE_LOG"
394 .IP "\s-1TYPE_NOTIF\s0" 4
395 .IX Item "TYPE_NOTIF"
396 .IP "\s-1TYPE_SHUTDOWN\s0" 4
397 .IX Item "TYPE_SHUTDOWN"
398 .IP "\s-1TYPE_DATASET\s0" 4
399 .IX Item "TYPE_DATASET"
400 .RE
401 .RS 4
402 .PD
403 .Sp
404 \&\fIname\fR is the name of the callback-function or the type of the data-set,
405 depending on the value of \fItype\fR. (Please note that the type of the data-set
406 is the value passed as \fIname\fR here and has nothing to do with the \fItype\fR
407 argument which simply tells \fBplugin_register\fR what is being registered.)
408 .Sp
409 The last argument, \fIdata\fR, is either a function name or an array-reference.
410 If \fItype\fR is \fB\s-1TYPE_DATASET\s0\fR, then the \fIdata\fR argument must be an
411 array-reference which points to an array of hashes. Each hash describes one
412 data-set. For the exact layout see \fBData-Set\fR above. Please note that
413 there is a large number of predefined data-sets available in the \fBtypes.db\fR
414 file which are automatically registered with collectd \- see \fItypes.db\fR\|(5) for
415 a description of the format of this file.
416 .Sp
417 \&\fBNote\fR: Using \fBplugin_register\fR to register a data-set is deprecated. Add
418 the new type to a custom \fItypes.db\fR\|(5) file instead. This functionality might
419 be removed in a future version of collectd.
420 .Sp
421 If the \fItype\fR argument is any of the other types (\fB\s-1TYPE_INIT\s0\fR, \fB\s-1TYPE_READ\s0\fR,
422 \&...) then \fIdata\fR is expected to be a function name. If the name is not
423 prefixed with the plugin's package name collectd will add it automatically.
424 The interface slightly differs from the C interface (which expects a function
425 pointer instead) because Perl does not support to share references to
426 subroutines between threads.
427 .Sp
428 These functions are called in the various stages of the daemon (see the
429 section \*(L"\s-1WRITING YOUR OWN PLUGINS\*(R"\s0 above) and are passed the following
430 arguments:
431 .IP "\s-1TYPE_CONFIG\s0" 4
432 .IX Item "TYPE_CONFIG"
433 The only argument passed is \fIconfig-item\fR. See above for the layout of this
434 data type.
435 .IP "\s-1TYPE_INIT\s0" 4
436 .IX Item "TYPE_INIT"
437 .PD 0
438 .IP "\s-1TYPE_READ\s0" 4
439 .IX Item "TYPE_READ"
440 .IP "\s-1TYPE_SHUTDOWN\s0" 4
441 .IX Item "TYPE_SHUTDOWN"
442 .PD
443 No arguments are passed.
444 .IP "\s-1TYPE_WRITE\s0" 4
445 .IX Item "TYPE_WRITE"
446 The arguments passed are \fItype\fR, \fIdata-set\fR, and \fIvalue-list\fR. \fItype\fR is a
447 string. For the layout of \fIdata-set\fR and \fIvalue-list\fR see above.
448 .IP "\s-1TYPE_FLUSH\s0" 4
449 .IX Item "TYPE_FLUSH"
450 The arguments passed are \fItimeout\fR and \fIidentifier\fR. \fItimeout\fR indicates
451 that only data older than \fItimeout\fR seconds is to be flushed. \fIidentifier\fR
452 specifies which values are to be flushed.
453 .IP "\s-1TYPE_LOG\s0" 4
454 .IX Item "TYPE_LOG"
455 The arguments are \fIlog-level\fR and \fImessage\fR. The log level is small for
456 important messages and high for less important messages. The least important
457 level is \fB\s-1LOG_DEBUG\s0\fR, the most important level is \fB\s-1LOG_ERR\s0\fR. In between there
458 are (from least to most important): \fB\s-1LOG_INFO\s0\fR, \fB\s-1LOG_NOTICE\s0\fR, and
459 \&\fB\s-1LOG_WARNING\s0\fR. \fImessage\fR is simply a string \fBwithout\fR a newline at the end.
460 .IP "\s-1TYPE_NOTIF\s0" 4
461 .IX Item "TYPE_NOTIF"
462 The only argument passed is \fInotification\fR. See above for the layout of this
463 data type.
464 .RE
465 .RS 4
466 .RE
467 .IP "\fBplugin_unregister\fR (\fItype\fR, \fIplugin\fR)" 4
468 .IX Item "plugin_unregister (type, plugin)"
469 Removes a callback or data-set from collectd's internal list of
470 functions\ / datasets.
471 .IP "\fBplugin_dispatch_values\fR (\fIvalue-list\fR)" 4
472 .IX Item "plugin_dispatch_values (value-list)"
473 Submits a \fIvalue-list\fR to the daemon. If the data-set identified by
474 \&\fIvalue-list\fR\->{\fItype\fR}
475 is found (and the number of values matches the number of data-sources) then the
476 type, data-set and value-list is passed to all write-callbacks that are
477 registered with the daemon.
478 .IP "\fBplugin_write\fR ([\fBplugins\fR => \fI...\fR][, \fBdatasets\fR => \fI...\fR], \fBvaluelists\fR => \fI...\fR)" 4
479 .IX Item "plugin_write ([plugins => ...][, datasets => ...], valuelists => ...)"
480 Calls the write function of the given \fIplugins\fR with the provided \fIdata
481 sets\fR and \fIvalue lists\fR. In contrast to \fBplugin_dispatch_values\fR, it does
482 not update collectd's internal cache and bypasses the filter mechanism (see
483 \&\fIcollectd.conf\fR\|(5) for details). If the \fBplugins\fR argument has been omitted,
484 the values will be dispatched to all registered write plugins. If the
485 \&\fBdatasets\fR argument has been omitted, the required data sets are looked up
486 according to the \f(CW\*(C`type\*(C'\fR member in the appropriate value list. The value of
487 all three arguments may either be a single scalar or a reference to an array.
488 If the \fBdatasets\fR argument has been specified, the number of data sets has to
489 equal the number of specified value lists.
490 .IP "\fBplugin_flush\fR ([\fBtimeout\fR => \fItimeout\fR][, \fBplugins\fR => \fI...\fR][, \fBidentifiers\fR => \fI...\fR])" 4
491 .IX Item "plugin_flush ([timeout => timeout][, plugins => ...][, identifiers => ...])"
492 Flush one or more plugins. \fItimeout\fR and the specified \fIidentifiers\fR are
493 passed on to the registered flush-callbacks. If omitted, the timeout defaults
494 to \f(CW\*(C`\-1\*(C'\fR. The identifier defaults to the undefined value. If the \fBplugins\fR
495 argument has been specified, only named plugins will be flushed. The value of
496 the \fBplugins\fR and \fBidentifiers\fR arguments may either be a string or a
497 reference to an array of strings.
498 .IP "\fBplugin_dispatch_notification\fR (\fInotification\fR)" 4
499 .IX Item "plugin_dispatch_notification (notification)"
500 Submits a \fInotification\fR to the daemon which will then pass it to all
501 notification-callbacks that are registered.
502 .IP "\fBplugin_log\fR (\fIlog-level\fR, \fImessage\fR)" 4
503 .IX Item "plugin_log (log-level, message)"
504 Submits a \fImessage\fR of level \fIlog-level\fR to collectd's logging mechanism.
505 The message is passed to all log-callbacks that are registered with collectd.
506 .IP "\fB\s-1ERROR\s0\fR, \fB\s-1WARNING\s0\fR, \fB\s-1NOTICE\s0\fR, \fB\s-1INFO\s0\fR, \fB\s-1DEBUG\s0\fR (\fImessage\fR)" 4
507 .IX Item "ERROR, WARNING, NOTICE, INFO, DEBUG (message)"
508 Wrappers around \fBplugin_log\fR, using \fB\s-1LOG_ERR\s0\fR, \fB\s-1LOG_WARNING\s0\fR,
509 \&\fB\s-1LOG_NOTICE\s0\fR, \fB\s-1LOG_INFO\s0\fR and \fB\s-1LOG_DEBUG\s0\fR respectively as \fIlog-level\fR.
510 .IP "\fBplugin_get_interval\fR ()" 4
511 .IX Item "plugin_get_interval ()"
512 Returns the interval of the current plugin as a floating point number in
513 seconds. This value depends on the interval configured within the
514 \&\f(CW\*(C`LoadPlugin perl\*(C'\fR block or the global interval (see \fIcollectd.conf\fR\|(5) for
515 details).
516 .PP
517 The following function provides the filter chain C\-interface to Perl-modules.
518 It is exported by the \*(L":filter_chain\*(R" export tag (see the section \*(L"\s-1EXPORTS\*(R"\s0
519 below).
520 .IP "\fBfc_register\fR (\fItype\fR, \fIname\fR, \fIproc\fR)" 4
521 .IX Item "fc_register (type, name, proc)"
522 Registers filter chain callbacks with collectd.
523 .Sp
524 \&\fItype\fR may be any of:
525 .RS 4
526 .IP "\s-1FC_MATCH\s0" 4
527 .IX Item "FC_MATCH"
528 .PD 0
529 .IP "\s-1FC_TARGET\s0" 4
530 .IX Item "FC_TARGET"
531 .RE
532 .RS 4
533 .PD
534 .Sp
535 \&\fIname\fR is the name of the match or target. By this name, the callbacks are
536 identified in the configuration file when specifying a \fBMatch\fR or \fBTarget\fR
537 block (see \fIcollectd.conf\fR\|(5) for details).
538 .Sp
539 \&\fIproc\fR is a hash reference. The hash includes up to three callbacks: an
540 optional constructor (\fBcreate\fR) and destructor (\fBdestroy\fR) and a mandatory
541 \&\fBmatch\fR or \fBinvoke\fR callback. \fBmatch\fR is called whenever processing an
542 appropriate match, while \fBinvoke\fR is called whenever processing an
543 appropriate target (see the section \*(L"\s-1FILTER CONFIGURATION\*(R"\s0 in
544 \&\fIcollectd.conf\fR\|(5) for details). Just like any other callbacks, filter chain
545 callbacks are identified by the function name rather than a function pointer
546 because Perl does not support to share references to subroutines between
547 threads. The following arguments are passed to the callbacks:
548 .IP "create" 4
549 .IX Item "create"
550 The arguments passed are \fIconfig-item\fR and \fIuser-data\fR. See above for the
551 layout of the config-item data-type. \fIuser-data\fR is a reference to a scalar
552 value that may be used to store any information specific to this particular
553 instance. The daemon does not care about this information at all. It's for the
554 plugin's use only.
555 .IP "destroy" 4
556 .IX Item "destroy"
557 The only argument passed is \fIuser-data\fR which is a reference to the user data
558 initialized in the \fBcreate\fR callback. This callback may be used to cleanup
559 instance-specific information and settings.
560 .IP "match, invoke" 4
561 .IX Item "match, invoke"
562 The arguments passed are \fIdata-set\fR, \fIvalue-list\fR, \fImeta\fR and \fIuser-data\fR.
563 See above for the layout of the data-set and value-list data-types. \fImeta\fR is
564 a pointer to an array of meta information, just like the \fBmeta\fR member of the
565 notification data-type (see above). \fIuser-data\fR is a reference to the user
566 data initialized in the \fBcreate\fR callback.
567 .RE
568 .RS 4
569 .RE
570 .SH "GLOBAL VARIABLES"
571 .IX Header "GLOBAL VARIABLES"
572 .ie n .IP "\fB\fB$hostname_g\fB\fR" 4
573 .el .IP "\fB\f(CB$hostname_g\fB\fR" 4
574 .IX Item "$hostname_g"
575 As the name suggests this variable keeps the hostname of the system collectd
576 is running on. The value might be influenced by the \fBHostname\fR or
577 \&\fBFQDNLookup\fR configuration options (see \fIcollectd.conf\fR\|(5) for details).
578 .ie n .IP "\fB\fB$interval_g\fB\fR" 4
579 .el .IP "\fB\f(CB$interval_g\fB\fR" 4
580 .IX Item "$interval_g"
581 This variable keeps the interval in seconds in which the read functions are
582 queried (see the \fBInterval\fR configuration option).
583 .Sp
584 \&\fBNote:\fR This variable should no longer be used in favor of
585 \&\f(CW\*(C`plugin_get_interval()\*(C'\fR (see above). This function takes any plugin-specific
586 interval settings into account (see the \f(CW\*(C`Interval\*(C'\fR option of \f(CW\*(C`LoadPlugin\*(C'\fR in
587 \&\fIcollectd.conf\fR\|(5) for details).
588 .PP
589 Any changes to these variables will be globally visible in collectd.
590 .SH "EXPORTS"
591 .IX Header "EXPORTS"
592 By default no symbols are exported. However, the following export tags are
593 available (\fB:all\fR will export all of them):
594 .IP "\fB:plugin\fR" 4
595 .IX Item ":plugin"
596 .RS 4
597 .PD 0
598 .IP "\fBplugin_register\fR ()" 4
599 .IX Item "plugin_register ()"
600 .IP "\fBplugin_unregister\fR ()" 4
601 .IX Item "plugin_unregister ()"
602 .IP "\fBplugin_dispatch_values\fR ()" 4
603 .IX Item "plugin_dispatch_values ()"
604 .IP "\fBplugin_flush\fR ()" 4
605 .IX Item "plugin_flush ()"
606 .IP "\fBplugin_flush_one\fR ()" 4
607 .IX Item "plugin_flush_one ()"
608 .IP "\fBplugin_flush_all\fR ()" 4
609 .IX Item "plugin_flush_all ()"
610 .IP "\fBplugin_dispatch_notification\fR ()" 4
611 .IX Item "plugin_dispatch_notification ()"
612 .IP "\fBplugin_log\fR ()" 4
613 .IX Item "plugin_log ()"
614 .RE
615 .RS 4
616 .RE
617 .IP "\fB:types\fR" 4
618 .IX Item ":types"
619 .RS 4
620 .IP "\fB\s-1TYPE_CONFIG\s0\fR" 4
621 .IX Item "TYPE_CONFIG"
622 .IP "\fB\s-1TYPE_INIT\s0\fR" 4
623 .IX Item "TYPE_INIT"
624 .IP "\fB\s-1TYPE_READ\s0\fR" 4
625 .IX Item "TYPE_READ"
626 .IP "\fB\s-1TYPE_WRITE\s0\fR" 4
627 .IX Item "TYPE_WRITE"
628 .IP "\fB\s-1TYPE_FLUSH\s0\fR" 4
629 .IX Item "TYPE_FLUSH"
630 .IP "\fB\s-1TYPE_SHUTDOWN\s0\fR" 4
631 .IX Item "TYPE_SHUTDOWN"
632 .IP "\fB\s-1TYPE_LOG\s0\fR" 4
633 .IX Item "TYPE_LOG"
634 .IP "\fB\s-1TYPE_DATASET\s0\fR" 4
635 .IX Item "TYPE_DATASET"
636 .RE
637 .RS 4
638 .RE
639 .IP "\fB:ds_types\fR" 4
640 .IX Item ":ds_types"
641 .RS 4
642 .IP "\fB\s-1DS_TYPE_COUNTER\s0\fR" 4
643 .IX Item "DS_TYPE_COUNTER"
644 .IP "\fB\s-1DS_TYPE_GAUGE\s0\fR" 4
645 .IX Item "DS_TYPE_GAUGE"
646 .IP "\fB\s-1DS_TYPE_DERIVE\s0\fR" 4
647 .IX Item "DS_TYPE_DERIVE"
648 .IP "\fB\s-1DS_TYPE_ABSOLUTE\s0\fR" 4
649 .IX Item "DS_TYPE_ABSOLUTE"
650 .RE
651 .RS 4
652 .RE
653 .IP "\fB:log\fR" 4
654 .IX Item ":log"
655 .RS 4
656 .IP "\fB\s-1ERROR\s0\fR ()" 4
657 .IX Item "ERROR ()"
658 .IP "\fB\s-1WARNING\s0\fR ()" 4
659 .IX Item "WARNING ()"
660 .IP "\fB\s-1NOTICE\s0\fR ()" 4
661 .IX Item "NOTICE ()"
662 .IP "\fB\s-1INFO\s0\fR ()" 4
663 .IX Item "INFO ()"
664 .IP "\fB\s-1DEBUG\s0\fR ()" 4
665 .IX Item "DEBUG ()"
666 .IP "\fB\s-1LOG_ERR\s0\fR" 4
667 .IX Item "LOG_ERR"
668 .IP "\fB\s-1LOG_WARNING\s0\fR" 4
669 .IX Item "LOG_WARNING"
670 .IP "\fB\s-1LOG_NOTICE\s0\fR" 4
671 .IX Item "LOG_NOTICE"
672 .IP "\fB\s-1LOG_INFO\s0\fR" 4
673 .IX Item "LOG_INFO"
674 .IP "\fB\s-1LOG_DEBUG\s0\fR" 4
675 .IX Item "LOG_DEBUG"
676 .RE
677 .RS 4
678 .RE
679 .IP "\fB:filter_chain\fR" 4
680 .IX Item ":filter_chain"
681 .RS 4
682 .IP "\fBfc_register\fR" 4
683 .IX Item "fc_register"
684 .IP "\fB\s-1FC_MATCH_NO_MATCH\s0\fR" 4
685 .IX Item "FC_MATCH_NO_MATCH"
686 .IP "\fB\s-1FC_MATCH_MATCHES\s0\fR" 4
687 .IX Item "FC_MATCH_MATCHES"
688 .IP "\fB\s-1FC_TARGET_CONTINUE\s0\fR" 4
689 .IX Item "FC_TARGET_CONTINUE"
690 .IP "\fB\s-1FC_TARGET_STOP\s0\fR" 4
691 .IX Item "FC_TARGET_STOP"
692 .IP "\fB\s-1FC_TARGET_RETURN\s0\fR" 4
693 .IX Item "FC_TARGET_RETURN"
694 .RE
695 .RS 4
696 .RE
697 .IP "\fB:fc_types\fR" 4
698 .IX Item ":fc_types"
699 .RS 4
700 .IP "\fB\s-1FC_MATCH\s0\fR" 4
701 .IX Item "FC_MATCH"
702 .IP "\fB\s-1FC_TARGET\s0\fR" 4
703 .IX Item "FC_TARGET"
704 .RE
705 .RS 4
706 .RE
707 .IP "\fB:notif\fR" 4
708 .IX Item ":notif"
709 .RS 4
710 .IP "\fB\s-1NOTIF_FAILURE\s0\fR" 4
711 .IX Item "NOTIF_FAILURE"
712 .IP "\fB\s-1NOTIF_WARNING\s0\fR" 4
713 .IX Item "NOTIF_WARNING"
714 .IP "\fB\s-1NOTIF_OKAY\s0\fR" 4
715 .IX Item "NOTIF_OKAY"
716 .RE
717 .RS 4
718 .RE
719 .IP "\fB:globals\fR" 4
720 .IX Item ":globals"
721 .RS 4
722 .ie n .IP "\fB\fB$hostname_g\fB\fR" 4
723 .el .IP "\fB\f(CB$hostname_g\fB\fR" 4
724 .IX Item "$hostname_g"
725 .ie n .IP "\fB\fB$interval_g\fB\fR" 4
726 .el .IP "\fB\f(CB$interval_g\fB\fR" 4
727 .IX Item "$interval_g"
728 .RE
729 .RS 4
730 .RE
731 .PD
732 .SH "EXAMPLES"
733 .IX Header "EXAMPLES"
734 Any Perl plugin will start similar to:
735 .PP
736 .Vb 1
737 \&  package Collectd::Plugins::FooBar;
738 \&
739 \&  use strict;
740 \&  use warnings;
741 \&
742 \&  use Collectd qw( :all );
743 .Ve
744 .PP
745 A very simple read function might look like:
746 .PP
747 .Vb 7
748 \&  sub foobar_read
749 \&  {
750 \&    my $vl = { plugin => \*(Aqfoobar\*(Aq, type => \*(Aqgauge\*(Aq };
751 \&    $vl\->{\*(Aqvalues\*(Aq} = [ rand(42) ];
752 \&    plugin_dispatch_values ($vl);
753 \&    return 1;
754 \&  }
755 .Ve
756 .PP
757 A very simple write function might look like:
758 .PP
759 .Vb 8
760 \&  sub foobar_write
761 \&  {
762 \&    my ($type, $ds, $vl) = @_;
763 \&    for (my $i = 0; $i < scalar (@$ds); ++$i) {
764 \&      print "$vl\->{\*(Aqplugin\*(Aq} ($vl\->{\*(Aqtype\*(Aq}): $vl\->{\*(Aqvalues\*(Aq}\->[$i]\en";
765 \&    }
766 \&    return 1;
767 \&  }
768 .Ve
769 .PP
770 A very simple match callback might look like:
771 .PP
772 .Vb 9
773 \&  sub foobar_match
774 \&  {
775 \&    my ($ds, $vl, $meta, $user_data) = @_;
776 \&    if (matches($ds, $vl)) {
777 \&      return FC_MATCH_MATCHES;
778 \&    } else {
779 \&      return FC_MATCH_NO_MATCH;
780 \&    }
781 \&  }
782 .Ve
783 .PP
784 To register those functions with collectd:
785 .PP
786 .Vb 2
787 \&  plugin_register (TYPE_READ, "foobar", "foobar_read");
788 \&  plugin_register (TYPE_WRITE, "foobar", "foobar_write");
789 \&
790 \&  fc_register (FC_MATCH, "foobar", "foobar_match");
791 .Ve
792 .PP
793 See the section \*(L"\s-1DATA TYPES\*(R"\s0 above for a complete documentation of the data
794 types used by the read, write and match functions.
795 .SH "NOTES"
796 .IX Header "NOTES"
797 .IP "\(bu" 4
798 Please feel free to send in new plugins to collectd's mailing list at
799 <collectd\ at\ collectd.org> for review and, possibly,
800 inclusion in the main distribution. In the latter case, we will take care of
801 keeping the plugin up to date and adapting it to new versions of collectd.
802 .Sp
803 Before submitting your plugin, please take a look at
804 <http://collectd.org/dev\-info.shtml>.
805 .SH "CAVEATS"
806 .IX Header "CAVEATS"
807 .IP "\(bu" 4
808 collectd is heavily multi-threaded. Each collectd thread accessing the perl
809 plugin will be mapped to a Perl interpreter thread (see \fIthreads\fR\|(3perl)).
810 Any such thread will be created and destroyed transparently and on-the-fly.
811 .Sp
812 Hence, any plugin has to be thread-safe if it provides several entry points
813 from collectd (i.\ e. if it registers more than one callback or if a
814 registered callback may be called more than once in parallel). Please note
815 that no data is shared between threads by default. You have to use the
816 \&\fBthreads::shared\fR module to do so.
817 .IP "\(bu" 4
818 Each function name registered with collectd has to be available before the
819 first thread has been created (i.\ e. basically at compile time). This
820 basically means that hacks (yes, I really consider this to be a hack) like
821 \&\f(CW\*(C`*foo = \e&bar; plugin_register (TYPE_READ, "plugin", "foo");\*(C'\fR most likely
822 will not work. This is due to the fact that the symbol table is not shared
823 across different threads.
824 .IP "\(bu" 4
825 Each plugin is usually only loaded once and kept in memory for performance
826 reasons. Therefore, \s-1END\s0 blocks are only executed once when collectd shuts
827 down. You should not rely on \s-1END\s0 blocks anyway \- use \fBshutdown functions\fR
828 instead.
829 .IP "\(bu" 4
830 The perl plugin exports the internal \s-1API\s0 of collectd which is considered
831 unstable and subject to change at any time. We try hard to not break backwards
832 compatibility in the Perl \s-1API\s0 during the life cycle of one major release.
833 However, this cannot be guaranteed at all times. Watch out for warnings
834 dispatched by the perl plugin after upgrades.
835 .SH "KNOWN BUGS"
836 .IX Header "KNOWN BUGS"
837 .IP "\(bu" 4
838 Currently, it is not possible to flush a single Perl plugin only. You can
839 either flush all Perl plugins or none at all and you have to use \f(CW\*(C`perl\*(C'\fR as
840 plugin name when doing so.
841 .SH "SEE ALSO"
842 .IX Header "SEE ALSO"
843 \&\fIcollectd\fR\|(1),
844 \&\fIcollectd.conf\fR\|(5),
845 \&\fIcollectd\-exec\fR\|(5),
846 \&\fItypes.db\fR\|(5),
847 \&\fIperl\fR\|(1),
848 \&\fIthreads\fR\|(3perl),
849 \&\fIthreads::shared\fR\|(3perl),
850 \&\fIperldebug\fR\|(1)
851 .SH "AUTHOR"
852 .IX Header "AUTHOR"
853 The \f(CW\*(C`perl plugin\*(C'\fR has been written by Sebastian Harl
854 <sh\ at\ tokkee.org>.
855 .PP
856 This manpage has been written by Florian Forster
857 <octo\ at\ collectd.org> and Sebastian Harl
858 <sh\ at\ tokkee.org>.