Code

Imported Upstream version 5.5.0
[pkg-collectd.git] / src / collectd-python.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-PYTHON 5"
136 .TH COLLECTD-PYTHON 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\-python \- Documentation of collectd's "python plugin"
143 .SH "SYNOPSIS"
144 .IX Header "SYNOPSIS"
145 .Vb 7
146 \&  LoadPlugin python
147 \&  # ...
148 \&  <Plugin python>
149 \&    ModulePath "/path/to/your/python/modules"
150 \&    LogTraces true
151 \&    Interactive false
152 \&    Import "spam"
153 \&
154 \&    <Module spam>
155 \&      spam "wonderful" "lovely"
156 \&    </Module>
157 \&  </Plugin>
158 .Ve
159 .SH "DESCRIPTION"
160 .IX Header "DESCRIPTION"
161 The \f(CW\*(C`python plugin\*(C'\fR embeds a Python-interpreter into collectd and provides an
162 interface to collectd's plugin system. This makes it possible to write plugins
163 for collectd in Python. This is a lot more efficient than executing a
164 Python-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 .PP
167 The minimum required Python version is \fI2.3\fR.
168 .SH "CONFIGURATION"
169 .IX Header "CONFIGURATION"
170 .IP "\fBLoadPlugin\fR \fIPlugin\fR" 4
171 .IX Item "LoadPlugin Plugin"
172 Loads the Python plugin \fIPlugin\fR.
173 .IP "\fBEncoding\fR \fIName\fR" 4
174 .IX Item "Encoding Name"
175 The default encoding for Unicode objects you pass to collectd. If you omit this
176 option it will default to \fBascii\fR on \fIPython 2\fR. On \fIPython 3\fR it will
177 always be \fButf\-8\fR, as this function was removed, so this will be silently
178 ignored.
179 These defaults are hardcoded in Python and will ignore everything else,
180 including your locale.
181 .IP "\fBModulePath\fR \fIName\fR" 4
182 .IX Item "ModulePath Name"
183 Prepends \fIName\fR to \fBsys.path\fR. You won't be able to import any scripts you
184 wrote unless they are located in one of the directories in this list. Please
185 note that it only has effect on plugins loaded after this option. You can
186 use multiple \fBModulePath\fR lines to add more than one directory.
187 .IP "\fBLogTraces\fR \fIbool\fR" 4
188 .IX Item "LogTraces bool"
189 If a Python script throws an exception it will be logged by collectd with the
190 name of the exception and the message. If you set this option to true it will
191 also log the full stacktrace just like the default output of an interactive
192 Python interpreter. This should probably be set to false most of the time but
193 is very useful for development and debugging of new modules.
194 .IP "\fBInteractive\fR \fIbool\fR" 4
195 .IX Item "Interactive bool"
196 This option will cause the module to launch an interactive Python interpreter
197 that reads from and writes to the terminal. Note that collectd will terminate
198 right after starting up if you try to run it as a daemon while this option is
199 enabled so make sure to start collectd with the \fB\-f\fR option.
200 .Sp
201 The \fBcollectd\fR module is \fInot\fR imported into the interpreter's globals. You
202 have to do it manually. Be sure to read the help text of the module, it can be
203 used as a reference guide during coding.
204 .Sp
205 This interactive session will behave slightly differently from a daemonized
206 collectd script as well as from a normal Python interpreter:
207 .RS 4
208 .IP "\(bu" 4
209 \&\fB1.\fR collectd will try to import the \fBreadline\fR module to give you a decent
210 way of entering your commands. The daemonized collectd won't do that.
211 .IP "\(bu" 4
212 \&\fB2.\fR collectd will block \fI\s-1SIGINT\s0\fR. Pressing \fICtrl+C\fR will usually cause
213 collectd to shut down. This would be problematic in an interactive session,
214 therefore this signal will be blocked. You can still use it to interrupt
215 syscalls like sleep and pause but it won't generate a \fIKeyboardInterrupt\fR
216 exception either.
217 .Sp
218 To quit collectd send \fI\s-1EOF\s0\fR (press \fICtrl+D\fR at the beginning of a new line).
219 .IP "\(bu" 4
220 \&\fB3.\fR collectd handles \fI\s-1SIGCHLD\s0\fR. This means that Python won't be able to
221 determine the return code of spawned processes with \fIsystem()\fR, \fIpopen()\fR and
222 subprocess. This will result in Python not using external programs like less
223 to display help texts. You can override this behavior with the \fB\s-1PAGER\s0\fR
224 environment variable, e.g. \fIexport PAGER=less\fR before starting collectd.
225 Depending on your version of Python this might or might not result in an
226 \&\fBOSError\fR exception which can be ignored.
227 .Sp
228 If you really need to spawn new processes from Python you can register an init
229 callback and reset the action for \s-1SIGCHLD\s0 to the default behavior. Please note
230 that this \fIwill\fR break the exec plugin. Do not even load the exec plugin if
231 you intend to do this!
232 .Sp
233 There is an example script located in \fBcontrib/python/getsigchld.py\fR  to do
234 this. If you import this from \fIcollectd.conf\fR \s-1SIGCHLD\s0 will be handled
235 normally and spawning processes from Python will work as intended.
236 .RE
237 .RS 4
238 .RE
239 .IP "<\fBModule\fR \fIName\fR> block" 4
240 .IX Item "<Module Name> block"
241 This block may be used to pass on configuration settings to a Python module.
242 The configuration is converted into an instance of the \fBConfig\fR class which is
243 passed to the registered configuration callback. See below for details about
244 the \fBConfig\fR class and how to register callbacks.
245 .Sp
246 The \fIname\fR identifies the callback.
247 .SH "STRINGS"
248 .IX Header "STRINGS"
249 There are a lot of places where strings are sent from collectd to Python and
250 from Python to collectd. How exactly this works depends on whether byte or
251 unicode strings or Python2 or Python3 are used.
252 .PP
253 Python2 has \fIstr\fR, which is just bytes, and \fIunicode\fR. Python3 has \fIstr\fR,
254 which is a unicode object, and \fIbytes\fR.
255 .PP
256 When passing strings from Python to collectd all of these object are supported
257 in all places, however \fIstr\fR should be used if possible. These strings must
258 not contain a \s-1NUL\s0 byte. Ignoring this will result in a \fITypeError\fR exception.
259 If a byte string was used it will be used as is by collectd. If a unicode
260 object was used it will be encoded using the default encoding (see above). If
261 this is not possible Python will raise a \fIUnicodeEncodeError\fR exception.
262 .PP
263 When passing strings from collectd to Python the behavior depends on the
264 Python version used. Python2 will always receive a \fIstr\fR object. Python3 will
265 usually receive a \fIstr\fR object as well, however the original string will be
266 decoded to unicode using the default encoding. If this fails because the
267 string is not a valid sequence for this encoding a \fIbytes\fR object will be
268 returned instead.
269 .SH "WRITING YOUR OWN PLUGINS"
270 .IX Header "WRITING YOUR OWN PLUGINS"
271 Writing your own plugins is quite simple. collectd manages plugins by means of
272 \&\fBdispatch functions\fR which call the appropriate \fBcallback functions\fR
273 registered by the plugins. Any plugin basically consists of the implementation
274 of these callback functions and initializing code which registers the
275 functions with collectd. See the section \*(L"\s-1EXAMPLES\*(R"\s0 below for a really basic
276 example. The following types of \fBcallback functions\fR are known to collectd
277 (all of them are optional):
278 .IP "configuration functions" 4
279 .IX Item "configuration functions"
280 These are called during configuration if an appropriate
281 \&\fBModule\fR block has been encountered. It is called once for each \fBModule\fR
282 block which matches the name of the callback as provided with the
283 \&\fBregister_config\fR method \- see below.
284 .Sp
285 Python thread support has not been initialized at this point so do not use any
286 threading functions here!
287 .IP "init functions" 4
288 .IX Item "init functions"
289 These are called once after loading the module and before any
290 calls to the read and write functions. It should be used to initialize the
291 internal state of the plugin (e.\ g. open sockets, ...). This is the
292 earliest point where you may use threads.
293 .IP "read functions" 4
294 .IX Item "read functions"
295 These are used to collect the actual data. It is called once
296 per interval (see the \fBInterval\fR configuration option of collectd). Usually
297 it will call \fBplugin_dispatch_values\fR to dispatch the values to collectd
298 which will pass them on to all registered \fBwrite functions\fR. If this function
299 throws any kind of exception the plugin will be skipped for an increasing
300 amount of time until it returns normally again.
301 .IP "write functions" 4
302 .IX Item "write functions"
303 These are used to write the dispatched values. It is called
304 once for every value that was dispatched by any plugin.
305 .IP "flush functions" 4
306 .IX Item "flush functions"
307 These are used to flush internal caches of plugins. It is
308 usually triggered by the user only. Any plugin which caches data before
309 writing it to disk should provide this kind of callback function.
310 .IP "log functions" 4
311 .IX Item "log functions"
312 These are used to pass messages of plugins or the daemon itself
313 to the user.
314 .IP "notification function" 4
315 .IX Item "notification function"
316 These are used to act upon notifications. In general, a
317 notification is a status message that may be associated with a data instance.
318 Usually, a notification is generated by the daemon if a configured threshold
319 has been exceeded (see the section \*(L"\s-1THRESHOLD CONFIGURATION\*(R"\s0 in
320 \&\fIcollectd.conf\fR\|(5) for more details), but any plugin may dispatch
321 notifications as well.
322 .IP "shutdown functions" 4
323 .IX Item "shutdown functions"
324 These are called once before the daemon shuts down. It should
325 be used to clean up the plugin (e.g. close sockets, ...).
326 .PP
327 Any function (except log functions) may throw an exception in case of
328 errors. The exception will be passed on to the user using collectd's logging
329 mechanism. If a log callback throws an exception it will be printed to standard
330 error instead.
331 .PP
332 See the documentation of the various \fBregister_\fR methods in the section
333 \&\*(L"\s-1FUNCTIONS\*(R"\s0 below for the number and types of arguments passed to each
334 \&\fBcallback function\fR. This section also explains how to register \fBcallback
335 functions\fR with collectd.
336 .PP
337 To enable a module, copy it to a place where Python can find it (i.\ e. a
338 directory listed in \fBsys.path\fR) just as any other Python plugin and add
339 an appropriate \fBImport\fR option to the configuration file. After restarting
340 collectd you're done.
341 .SH "CLASSES"
342 .IX Header "CLASSES"
343 The following complex types are used to pass values between the Python plugin
344 and collectd:
345 .SS "Signed"
346 .IX Subsection "Signed"
347 The Signed class is just a long. It has all its methods and behaves exactly
348 like any other long object. It is used to indicate if an integer was or should
349 be stored as a signed or unsigned integer object.
350 .PP
351 .Vb 1
352 \& class Signed(long)
353 .Ve
354 .PP
355 This is a long by another name. Use it in meta data dicts
356 to choose the way it is stored in the meta data.
357 .SS "Unsigned"
358 .IX Subsection "Unsigned"
359 The Unsigned class is just a long. It has all its methods and behaves exactly
360 like any other long object. It is used to indicate if an integer was or should
361 be stored as a signed or unsigned integer object.
362 .PP
363 .Vb 1
364 \& class Unsigned(long)
365 .Ve
366 .PP
367 This is a long by another name. Use it in meta data dicts
368 to choose the way it is stored in the meta data.
369 .SS "Config"
370 .IX Subsection "Config"
371 The Config class is an object which keeps the information provided in the
372 configuration file. The sequence of children keeps one entry for each
373 configuration option. Each such entry is another Config instance, which
374 may nest further if nested blocks are used.
375 .PP
376 .Vb 1
377 \& class Config(object)
378 .Ve
379 .PP
380 This represents a piece of collectd's config file. It is passed to scripts with
381 config callbacks (see \fBregister_config\fR) and is of little use if created
382 somewhere else.
383 .PP
384 It has no methods beyond the bare minimum and only exists for its data members.
385 .PP
386 Data descriptors defined here:
387 .IP "parent" 4
388 .IX Item "parent"
389 This represents the parent of this node. On the root node
390 of the config tree it will be None.
391 .IP "key" 4
392 .IX Item "key"
393 This is the keyword of this item, i.e. the first word of any given line in the
394 config file. It will always be a string.
395 .IP "values" 4
396 .IX Item "values"
397 This is a tuple (which might be empty) of all value, i.e. words following the
398 keyword in any given line in the config file.
399 .Sp
400 Every item in this tuple will be either a string, a float or a boolean,
401 depending on the contents of the configuration file.
402 .IP "children" 4
403 .IX Item "children"
404 This is a tuple of child nodes. For most nodes this will be empty. If this node
405 represents a block instead of a single line of the config file it will contain
406 all nodes in this block.
407 .SS "PluginData"
408 .IX Subsection "PluginData"
409 This should not be used directly but it is the base class for both Values and
410 Notification. It is used to identify the source of a value or notification.
411 .PP
412 .Vb 1
413 \& class PluginData(object)
414 .Ve
415 .PP
416 This is an internal class that is the base for Values and Notification. It is
417 pretty useless by itself and was therefore not exported to the collectd module.
418 .PP
419 Data descriptors defined here:
420 .IP "host" 4
421 .IX Item "host"
422 The hostname of the host this value was read from. For dispatching this can be
423 set to an empty string which means the local hostname as defined in
424 collectd.conf.
425 .IP "plugin" 4
426 .IX Item "plugin"
427 The name of the plugin that read the data. Setting this member to an empty
428 string will insert \*(L"python\*(R" upon dispatching.
429 .IP "plugin_instance" 4
430 .IX Item "plugin_instance"
431 Plugin instance string. May be empty.
432 .IP "time" 4
433 .IX Item "time"
434 This is the Unix timestamp of the time this value was read. For dispatching
435 values this can be set to zero which means \*(L"now\*(R". This means the time the value
436 is actually dispatched, not the time it was set to 0.
437 .IP "type" 4
438 .IX Item "type"
439 The type of this value. This type has to be defined in your \fItypes.db\fR.
440 Attempting to set it to any other value will raise a \fITypeError\fR exception.
441 Assigning a type is mandatory, calling dispatch without doing so will raise a
442 \&\fIRuntimeError\fR exception.
443 .IP "type_instance" 4
444 .IX Item "type_instance"
445 Type instance string. May be empty.
446 .SS "Values"
447 .IX Subsection "Values"
448 A Value is an object which features a sequence of values. It is based on the
449 \&\fIPluginData\fR type and uses its members to identify the values.
450 .PP
451 .Vb 1
452 \& class Values(PluginData)
453 .Ve
454 .PP
455 A Values object used for dispatching values to collectd and receiving values
456 from write callbacks.
457 .PP
458 Method resolution order:
459 .IP "Values" 4
460 .IX Item "Values"
461 .PD 0
462 .IP "PluginData" 4
463 .IX Item "PluginData"
464 .IP "object" 4
465 .IX Item "object"
466 .PD
467 .PP
468 Methods defined here:
469 .IP "\fBdispatch\fR([type][, values][, plugin_instance][, type_instance][, plugin][, host][, time][, interval]) \-> None." 4
470 .IX Item "dispatch([type][, values][, plugin_instance][, type_instance][, plugin][, host][, time][, interval]) -> None."
471 Dispatch this instance to the collectd process. The object has members for each
472 of the possible arguments for this method. For a detailed explanation of these
473 parameters see the member of the same same.
474 .Sp
475 If you do not submit a parameter the value saved in its member will be
476 submitted. If you do provide a parameter it will be used instead, without
477 altering the member.
478 .IP "\fBwrite\fR([destination][, type][, values][, plugin_instance][, type_instance][, plugin][, host][, time][, interval]) \-> None." 4
479 .IX Item "write([destination][, type][, values][, plugin_instance][, type_instance][, plugin][, host][, time][, interval]) -> None."
480 Write this instance to a single plugin or all plugins if \*(L"destination\*(R" is
481 omitted. This will bypass the main collectd process and all filtering and
482 caching. Other than that it works similar to \*(L"dispatch\*(R". In most cases
483 \&\*(L"dispatch\*(R" should be used instead of \*(L"write\*(R".
484 .PP
485 Data descriptors defined here:
486 .IP "interval" 4
487 .IX Item "interval"
488 The interval is the timespan in seconds between two submits for the same data
489 source. This value has to be a positive integer, so you can't submit more than
490 one value per second. If this member is set to a non-positive value, the
491 default value as specified in the config file will be used (default: 10).
492 .Sp
493 If you submit values more often than the specified interval, the average will
494 be used. If you submit less values, your graphs will have gaps.
495 .IP "values" 4
496 .IX Item "values"
497 These are the actual values that get dispatched to collectd. It has to be a
498 sequence (a tuple or list) of numbers. The size of the sequence and the type of
499 its content depend on the type member your \fItypes.db\fR file. For more
500 information on this read the \fItypes.db\fR\|(5) manual page.
501 .Sp
502 If the sequence does not have the correct size upon dispatch a \fIRuntimeError\fR
503 exception will be raised. If the content of the sequence is not a number, a
504 \&\fITypeError\fR exception will be raised.
505 .IP "meta" 4
506 .IX Item "meta"
507 These are the meta data for this Value object.
508 It has to be a dictionary of numbers, strings or bools. All keys must be
509 strings. \fIint\fR and <long> objects will be dispatched as signed integers unless
510 they are between 2**63 and 2**64\-1, which will result in a unsigned integer.
511 You can force one of these storage classes by using the classes
512 \&\fBcollectd.Signed\fR and \fBcollectd.Unsigned\fR. A meta object received by a write
513 callback will always contain \fBSigned\fR or \fBUnsigned\fR objects.
514 .SS "Notification"
515 .IX Subsection "Notification"
516 A notification is an object defining the severity and message of the status
517 message as well as an identification of a data instance by means of the members
518 of \fIPluginData\fR on which it is based.
519 .PP
520 class Notification(PluginData)
521 The Notification class is a wrapper around the collectd notification.
522 It can be used to notify other plugins about bad stuff happening. It works
523 similar to Values but has a severity and a message instead of interval
524 and time.
525 Notifications can be dispatched at any time and can be received with
526 register_notification.
527 .PP
528 Method resolution order:
529 .IP "Notification" 4
530 .IX Item "Notification"
531 .PD 0
532 .IP "PluginData" 4
533 .IX Item "PluginData"
534 .IP "object" 4
535 .IX Item "object"
536 .PD
537 .PP
538 Methods defined here:
539 .IP "\fBdispatch\fR([type][, values][, plugin_instance][, type_instance][, plugin][, host][, time][, interval]) \-> None.  Dispatch a value list." 4
540 .IX Item "dispatch([type][, values][, plugin_instance][, type_instance][, plugin][, host][, time][, interval]) -> None. Dispatch a value list."
541 Dispatch this instance to the collectd process. The object has members for each
542 of the possible arguments for this method. For a detailed explanation of these
543 parameters see the member of the same same.
544 .Sp
545 If you do not submit a parameter the value saved in its member will be
546 submitted. If you do provide a parameter it will be used instead, without
547 altering the member.
548 .PP
549 Data descriptors defined here:
550 .IP "message" 4
551 .IX Item "message"
552 Some kind of description of what's going on and why this Notification was
553 generated.
554 .IP "severity" 4
555 .IX Item "severity"
556 The severity of this notification. Assign or compare to \fI\s-1NOTIF_FAILURE\s0\fR,
557 \&\fI\s-1NOTIF_WARNING\s0\fR or \fI\s-1NOTIF_OKAY\s0\fR.
558 .SH "FUNCTIONS"
559 .IX Header "FUNCTIONS"
560 The following functions provide the C\-interface to Python-modules.
561 .IP "\fBregister_*\fR(\fIcallback\fR[, \fIdata\fR][, \fIname\fR]) \-> identifier" 4
562 .IX Item "register_*(callback[, data][, name]) -> identifier"
563 There are eight different register functions to get callback for eight
564 different events. With one exception all of them are called as shown above.
565 .RS 4
566 .IP "\(bu" 4
567 \&\fIcallback\fR is a callable object that will be called every time the event is
568 triggered.
569 .IP "\(bu" 4
570 \&\fIdata\fR is an optional object that will be passed back to the callback function
571 every time it is called. If you omit this parameter no object is passed back to
572 your callback, not even None.
573 .IP "\(bu" 4
574 \&\fIname\fR is an optional identifier for this callback. The default name is
575 \&\fBpython\fR.\fImodule\fR. \fImodule\fR is taken from the \fB_\|_module_\|_\fR attribute of
576 your callback function. Every callback needs a unique identifier, so if you
577 want to register the same callback multiple times in the same module you need to
578 specify a name here. Otherwise it's safe to ignore this parameter.
579 .IP "\(bu" 4
580 \&\fIidentifier\fR is the full identifier assigned to this callback.
581 .RE
582 .RS 4
583 .Sp
584 These functions are called in the various stages of the daemon (see the section
585 \&\*(L"\s-1WRITING YOUR OWN PLUGINS\*(R"\s0 above) and are passed the following arguments:
586 .IP "register_config" 4
587 .IX Item "register_config"
588 The only argument passed is a \fIConfig\fR object. See above for the layout of this
589 data type.
590 Note that you cannot receive the whole config files this way, only \fBModule\fR
591 blocks inside the Python configuration block. Additionally you will only
592 receive blocks where your callback identifier matches \fBpython.\fR\fIblockname\fR.
593 .IP "register_init" 4
594 .IX Item "register_init"
595 The callback will be called without arguments.
596 .IP "register_read(callback[, interval][, data][, name]) \-> \fIidentifier\fR" 4
597 .IX Item "register_read(callback[, interval][, data][, name]) -> identifier"
598 This function takes an additional parameter: \fIinterval\fR. It specifies the
599 time between calls to the callback function.
600 .Sp
601 The callback will be called without arguments.
602 .IP "register_shutdown" 4
603 .IX Item "register_shutdown"
604 The callback will be called without arguments.
605 .IP "register_write" 4
606 .IX Item "register_write"
607 The callback function will be called with one argument passed, which will be a
608 \&\fIValues\fR object. For the layout of \fIValues\fR see above.
609 If this callback function throws an exception the next call will be delayed by
610 an increasing interval.
611 .IP "register_flush" 4
612 .IX Item "register_flush"
613 Like \fBregister_config\fR is important for this callback because it determines
614 what flush requests the plugin will receive.
615 .Sp
616 The arguments passed are \fItimeout\fR and \fIidentifier\fR. \fItimeout\fR indicates
617 that only data older than \fItimeout\fR seconds is to be flushed. \fIidentifier\fR
618 specifies which values are to be flushed.
619 .IP "register_log" 4
620 .IX Item "register_log"
621 The arguments are \fIseverity\fR and \fImessage\fR. The severity is an integer and
622 small for important messages and high for less important messages. The least
623 important level is \fB\s-1LOG_DEBUG\s0\fR, the most important level is \fB\s-1LOG_ERR\s0\fR. In
624 between there are (from least to most important): \fB\s-1LOG_INFO\s0\fR, \fB\s-1LOG_NOTICE\s0\fR,
625 and \fB\s-1LOG_WARNING\s0\fR. \fImessage\fR is simply a string \fBwithout\fR a newline at the
626 end.
627 .Sp
628 If this callback throws an exception it will \fBnot\fR be logged. It will just be
629 printed to \fBsys.stderr\fR which usually means silently ignored.
630 .IP "register_notification" 4
631 .IX Item "register_notification"
632 The only argument passed is a \fINotification\fR object. See above for the layout of this
633 data type.
634 .RE
635 .RS 4
636 .RE
637 .IP "\fBunregister_*\fR(\fIidentifier\fR) \-> None" 4
638 .IX Item "unregister_*(identifier) -> None"
639 Removes a callback or data-set from collectd's internal list of callback
640 functions. Every \fIregister_*\fR function has an \fIunregister_*\fR function.
641 \&\fIidentifier\fR is either the string that was returned by the register function
642 or a callback function. The identifier will be constructed in the same way as
643 for the register functions.
644 .IP "\fBget_dataset\fR(\fIname\fR) \-> \fIdefinition\fR" 4
645 .IX Item "get_dataset(name) -> definition"
646 Returns the definition of a dataset specified by \fIname\fR. \fIdefinition\fR is a list
647 of tuples, each representing one data source. Each tuple has 4 values:
648 .RS 4
649 .IP "name" 4
650 .IX Item "name"
651 A string, the name of the data source.
652 .IP "type" 4
653 .IX Item "type"
654 A string that is equal to either of the variables \fB\s-1DS_TYPE_COUNTER\s0\fR,
655 \&\fB\s-1DS_TYPE_GAUGE\s0\fR, \fB\s-1DS_TYPE_DERIVE\s0\fR or \fB\s-1DS_TYPE_ABSOLUTE\s0\fR.
656 .IP "min" 4
657 .IX Item "min"
658 A float or None, the minimum value.
659 .IP "max" 4
660 .IX Item "max"
661 A float or None, the maximum value.
662 .RE
663 .RS 4
664 .RE
665 .IP "\fBflush\fR(\fIplugin\fR[, \fItimeout\fR][, \fIidentifier\fR]) \-> None" 4
666 .IX Item "flush(plugin[, timeout][, identifier]) -> None"
667 Flush one or all plugins. \fItimeout\fR and the specified \fIidentifiers\fR are
668 passed on to the registered flush-callbacks. If omitted, the timeout defaults
669 to \f(CW\*(C`\-1\*(C'\fR. The identifier defaults to None. If the \fBplugin\fR argument has been
670 specified, only named plugin will be flushed.
671 .IP "\fBerror\fR, \fBwarning\fR, \fBnotice\fR, \fBinfo\fR, \fBdebug\fR(\fImessage\fR)" 4
672 .IX Item "error, warning, notice, info, debug(message)"
673 Log a message with the specified severity.
674 .SH "EXAMPLES"
675 .IX Header "EXAMPLES"
676 Any Python module will start similar to:
677 .PP
678 .Vb 1
679 \&  import collectd
680 .Ve
681 .PP
682 A very simple read function might look like:
683 .PP
684 .Vb 4
685 \&  def read(data=None):
686 \&    vl = collectd.Values(type=\*(Aqgauge\*(Aq)
687 \&    vl.plugin=\*(Aqpython.spam\*(Aq
688 \&    vl.dispatch(values=[random.random() * 100])
689 .Ve
690 .PP
691 A very simple write function might look like:
692 .PP
693 .Vb 3
694 \&  def write(vl, data=None):
695 \&    for i in vl.values:
696 \&      print "%s (%s): %f" % (vl.plugin, vl.type, i)
697 .Ve
698 .PP
699 To register those functions with collectd:
700 .PP
701 .Vb 2
702 \&  collectd.register_read(read);
703 \&  collectd.register_write(write);
704 .Ve
705 .PP
706 See the section \*(L"\s-1CLASSES\*(R"\s0 above for a complete documentation of the data
707 types used by the read, write and match functions.
708 .SH "NOTES"
709 .IX Header "NOTES"
710 .IP "\(bu" 4
711 Please feel free to send in new plugins to collectd's mailing list at
712 <collectd\ at\ collectd.org> for review and, possibly,
713 inclusion in the main distribution. In the latter case, we will take care of
714 keeping the plugin up to date and adapting it to new versions of collectd.
715 .Sp
716 Before submitting your plugin, please take a look at
717 <http://collectd.org/dev\-info.shtml>.
718 .SH "CAVEATS"
719 .IX Header "CAVEATS"
720 .IP "\(bu" 4
721 collectd is heavily multi-threaded. Each collectd thread accessing the Python
722 plugin will be mapped to a Python interpreter thread. Any such thread will be
723 created and destroyed transparently and on-the-fly.
724 .Sp
725 Hence, any plugin has to be thread-safe if it provides several entry points
726 from collectd (i.\ e. if it registers more than one callback or if a
727 registered callback may be called more than once in parallel).
728 .IP "\(bu" 4
729 The Python thread module is initialized just before calling the init callbacks.
730 This means you must not use Python's threading module prior to this point. This
731 includes all config and possibly other callback as well.
732 .IP "\(bu" 4
733 The python plugin exports the internal \s-1API\s0 of collectd which is considered
734 unstable and subject to change at any time. We try hard to not break backwards
735 compatibility in the Python \s-1API\s0 during the life cycle of one major release.
736 However, this cannot be guaranteed at all times. Watch out for warnings
737 dispatched by the python plugin after upgrades.
738 .SH "KNOWN BUGS"
739 .IX Header "KNOWN BUGS"
740 .IP "\(bu" 4
741 Not all aspects of the collectd \s-1API\s0 are accessible from Python. This includes
742 but is not limited to filters and data sets.
743 .SH "SEE ALSO"
744 .IX Header "SEE ALSO"
745 \&\fIcollectd\fR\|(1),
746 \&\fIcollectd.conf\fR\|(5),
747 \&\fIcollectd\-perl\fR\|(5),
748 \&\fIcollectd\-exec\fR\|(5),
749 \&\fItypes.db\fR\|(5),
750 \&\fIpython\fR\|(1),
751 .SH "AUTHOR"
752 .IX Header "AUTHOR"
753 The \f(CW\*(C`python plugin\*(C'\fR has been written by
754 Sven Trenkel <collectd\ at\ semidefinite.de>.
755 .PP
756 This manpage has been written by Sven Trenkel
757 <collectd\ at\ semidefinite.de>.
758 It is based on the \fIcollectd\-perl\fR\|(5) manual page by
759 Florian Forster <octo\ at\ collectd.org> and
760 Sebastian Harl <sh\ at\ tokkee.org>.