X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fcollectd-perl.pod;h=b7ae9cace9c89f636172c1d27e5ccc5fbd4b3c9c;hb=654783aed1fab02766a9cc036e859799e01f6f9e;hp=842d0bb913218bc96f28727451e93b67c69645bd;hpb=f400d0708fc49deef428f6e487e1f65005f903d0;p=collectd.git diff --git a/src/collectd-perl.pod b/src/collectd-perl.pod index 842d0bb9..b7ae9cac 100644 --- a/src/collectd-perl.pod +++ b/src/collectd-perl.pod @@ -21,9 +21,6 @@ for collectd in Perl. This is a lot more efficient than executing a Perl-script every time you want to read a value with the C (see L) and provides a lot more functionality, too. -Please note that this is still considered to be experimental and subject to -change between minor releases. - =head1 CONFIGURATION =over 4 @@ -64,13 +61,13 @@ only has effect on plugins loaded after this option. =head1 WRITING YOUR OWN PLUGINS -Writing your own plugins is quite simply. collectd manages plugins by means of +Writing your own plugins is quite simple. collectd manages plugins by means of B which call the appropriate B registered by the plugins. Any plugin basically consists of the implementation of these callback functions and initializing code which registers the functions with collectd. See the section "EXAMPLES" below for a really basic example. The following types of B are known to collectd -(all of these are optional): +(all of them are optional): =over 4 @@ -95,11 +92,26 @@ amount of time until it returns B again. This type of function is used to write the dispatched values. It is called once for each call to B. +=item flush functions + +This type of function is used to flush internal caches of plugins. It is +usually triggered by the user only. Any plugin which caches data before +writing it to disk should provide this kind of callback function. + =item log functions This type of function is used to pass messages of plugins or the daemon itself to the user. +=item notification function + +This type of function is used to act upon notifications. In general, a +notification is a status message that may be associated with a data instance. +Usually, a notification is generated by the daemon if a configured threshold +has been exceeded (see the section "THRESHOLD CONFIGURATION" in +L for more details), but any plugin may dispatch +notifications as well. + =item shutdown functions This type of function is called once before the daemon shuts down. It should @@ -107,8 +119,9 @@ be used to clean up the plugin (e.g. close sockets, ...). =back -Any function may set the B<$@> variable to describe errors in more detail. The -message will be passed on to the user using collectd's logging mechanism. +Any function (except log functions) may set the B<$@> variable to describe +errors in more detail. The message will be passed on to the user using +collectd's logging mechanism. See the documentation of the B method in the section "METHODS" below for the number and types of arguments passed to each @@ -135,7 +148,7 @@ structure. The general layout looks like this: [{ name => 'data_source_name', - type => DS_TYPE_COUNTER || DS_TYPE_GAUGE + type => DS_TYPE_COUNTER || DS_TYPE_GAUGE, min => value || undef, max => value || undef }, ...] @@ -151,8 +164,25 @@ layout looks like this: { values => [123, 0.5], time => time (), - host => 'localhost', + host => $hostname_g, plugin => 'myplugin', + type => 'myplugin', + plugin_instance => '', + type_instance => '' + } + +=item Notification + +A notification is one structure defining the severity, time and message of the +status message as well as an identification of a data instance: + + { + severity => NOTIF_FAILURE || NOTIF_WARNING || NOTIF_OKAY, + time => time (), + message => 'status message', + host => $hostname_g, + plugin => 'myplugin', + type => 'mytype', plugin_instance => '', type_instance => '' } @@ -180,8 +210,12 @@ I can be one of: =item TYPE_WRITE +=item TYPE_FLUSH + =item TYPE_LOG +=item TYPE_NOTIF + =item TYPE_SHUTDOWN =item TYPE_DATASET @@ -196,9 +230,10 @@ argument which simply tells B what is being registered.) The last argument, I, is either a function name or an array-reference. If I is B, then the I argument must be an array-reference which points to an array of hashes. Each hash describes one -data-source. For the exact layout see B above. Please note that +data-set. For the exact layout see B above. Please note that there is a large number of predefined data-sets available in the B -file which are automatically registered with collectd. +file which are automatically registered with collectd - see L for +a description of the format of this file. If the I argument is any of the other types (B, B, ...) then I is expected to be a function name. If the name is not @@ -219,13 +254,18 @@ arguments: =item TYPE_SHUTDOWN -No arguments are passed +No arguments are passed. =item TYPE_WRITE The arguments passed are I, I, and I. I is a string. For the layout of I and I see above. +=item TYPE_FLUSH + +The only argument passed is I which indicates that only data older +than I seconds is to be flushed. + =item TYPE_LOG The arguments are I and I. The log level is small for @@ -234,6 +274,11 @@ level is B, the most important level is B. In between there are (from least to most important): B, B, and B. I is simply a string B a newline at the end. +=item TYPE_NOTIF + +The only argument passed is I. See above for the layout of this +data type. + =back =item B (I, I) @@ -241,13 +286,40 @@ B. I is simply a string B a newline at the end. Removes a callback or data-set from collectd's internal list of functionsE/ datasets. -=item B (I, I) +=item B (I) -Submits a I of type I to the daemon. If the data-set I +Submits a I to the daemon. If the data-set identified by +I->{I} is found (and the number of values matches the number of data-sources) then the type, data-set and value-list is passed to all write-callbacks that are registered with the daemon. +B: Prior to version 4.4 of collectd, the data-set type used to be passed +as the first argument to B. This syntax is still supported +for backwards compatibility but has been deprecated and will be removed in +some future version of collectd. + +=item B ([B => I,] [B => I<...>]) + +Flush one or more plugins. I is passed on to the registered +flush-callbacks. If omitted, C<-1> is used. If the I argument has +been specified, only named plugins will be flushed. The argument's value may +either be a string or a reference to an array of strings. + +=item B (I, I) + +This is identical to using "plugin_flush (timeout =E I, plugins +=E I". + +=item B (I) + +This is identical to using "plugin_flush (timeout =E I)". + +=item B (I) + +Submits a I to the daemon which will then pass it to all +notification-callbacks that are registered. + =item B (I, I) Submits a I of level I to collectd's logging mechanism. @@ -260,6 +332,25 @@ B, B and B respectively as I. =back +=head1 GLOBAL VARIABLES + +=over 4 + +=item B<$hostname_g> + +As the name suggests this variable keeps the hostname of the system collectd +is running on. The value might be influenced by the B or +B configuration options (see L for details). + +=item B<$interval_g> + +This variable keeps the interval in seconds in which the read functions are +queried (see the B configuration option). + +=back + +Any changes to these variables will be globally visible in collectd. + =head1 EXPORTS By default no symbols are exported. However, the following export tags are @@ -277,6 +368,14 @@ available (B<:all> will export all of them): =item B () +=item B () + +=item B () + +=item B () + +=item B () + =item B () =back @@ -291,6 +390,8 @@ available (B<:all> will export all of them): =item B +=item B + =item B =item B @@ -333,6 +434,28 @@ available (B<:all> will export all of them): =back +=item B<:notif> + +=over 4 + +=item B + +=item B + +=item B + +=back + +=item B<:globals> + +=over 4 + +=item B<$hostname_g> + +=item B<$interval_g> + +=back + =back =head1 EXAMPLES @@ -375,19 +498,77 @@ To register those functions with collectd: See the section "DATA TYPES" above for a complete documentation of the data types used by the read and write functions. -=head1 BUGS +=head1 NOTES + +=over 4 + +=item + +Please feel free to send in new plugins to collectd's mailinglist at +EcollectdEatEverplant.orgE for review and, possibly, +inclusion in the main distribution. In the latter case, we will take care of +keeping the plugin up to date and adapting it to new versions of collectd. + +Before submitting your plugin, please take a look at +L. -This plugin does not yet work correctly if collectd uses multiple threads. -Perl does not allow multiple threads to access a single interpreter at the -same time. As a temporary workaround you should use a single read thread only -(see collectd's B configuration option). +=back + +=head1 CAVEATS + +=over 4 + +=item + +collectd is heavily multi-threaded. Each collectd thread accessing the perl +plugin will be mapped to a Perl interpreter thread (see L). +Any such thread will be created and destroyed transparently and on-the-fly. + +Hence, any plugin has to be thread-safe if it provides several entry points +from collectd (i.Ee. if it registers more than one callback or if a +registered callback may be called more than once in parallel). Please note +that no data is shared between threads by default. You have to use the +B module to do so. + +=item + +Each function name registered with collectd has to be available before the +first thread has been created (i.Ee. basically at compile time). This +basically means that hacks (yes, I really consider this to be a hack) like +C<*foo = \&bar; plugin_register (TYPE_READ, "plugin", "foo");> most likely +will not work. This is due to the fact that the symbol table is not shared +across different threads. + +=item + +Each plugin is usually only loaded once and kept in memory for performance +reasons. Therefore, END blocks are only executed once when collectd shuts +down. You should not rely on END blocks anyway - use B +instead. + +=back + +=head1 KNOWN BUGS + +=over 4 + +=item + +Currently, it is not possible to flush a single Perl plugin only. You can +either flush all Perl plugins or none at all and you have to use C as +plugin name when doing so. + +=back =head1 SEE ALSO L, L, L, +L, L, +L, +L, L =head1 AUTHOR