Code

java plugin: Add support for `log' callbacks.
[collectd.git] / src / collectd-java.pod
1 =head1 NAME
3 collectd-java - Documentation of collectd's "java plugin"
5 =head1 SYNOPSIS
7  LoadPlugin "java"
8  <Plugin "java">
9    JVMArg "-verbose:jni"
10    JVMArg "-Djava.class.path=/opt/collectd/lib/collectd/bindings/java"
11    
12    LoadPlugin "org.collectd.java.Foobar"
13    <Plugin "org.collectd.java.Foobar">
14      # To be parsed by the plugin
15    </Plugin>
16  </Plugin>
18 =head1 DESCRIPTION
20 The I<Java> plugin embeds a I<Java Virtual Machine> (JVM) into I<collectd> and
21 provides a Java interface to part of collectd's API. This makes it possible to
22 write additions to the daemon in Java.
24 This plugin is similar in nature to, but shares no code with, the I<Perl>
25 plugin by Sebastian Harl, see L<collectd-perl(5)> for details.
27 =head1 CONFIGURATION
29 A short outline of this plugin's configuration can be seen in L<"SYNOPSIS">
30 above. For a complete list of all configuration options and their semantics
31 please read L<collectd.conf(5)/Plugin C<java>>.
33 =head1 OVERVIEW
35 When writing additions for collectd in Java, the underlying C base is mostly
36 hidden from you. All complex data types are converted to their Java counterparts
37 before they're passed to your functions. These Java classes reside in the
38 I<org.collectd.api> namespace.
40 The available classes are:
42 =over 4
44 =item B<org.collectd.api.OConfigValue>
46 Corresponds to C<oconfig_value_t>, defined in F<src/liboconfig/oconfig.h>.
48 =item B<org.collectd.api.OConfigItem>
50 Corresponds to C<oconfig_item_t>, defined in F<src/liboconfig/oconfig.h>.
52 =item B<org.collectd.api.DataSource>
54 Corresponds to C<data_source_t>, defined in F<src/plugin.h>.
56 =item B<org.collectd.api.DataSet>
58 Corresponds to C<data_set_t>, defined in F<src/plugin.h>.
60 =item B<org.collectd.api.ValueList>
62 Corresponds to C<value_list_t>, defined in F<src/plugin.h>.
64 =back
66 In the remainder of this document, we'll use the short form of these names, for
67 example B<ValueList>. In order to be able to use these abbreviated names, you
68 need to B<import> the classes.
70 The API functions that are available from Java are implemented as I<static>
71 functions of the B<org.collectd.api.Collectd> class.
72 See L<"CALLING API FUNCTIONS"> below for details.
74 =head1 REGISTERING CALLBACKS
76 When starting up, collectd creates an object of each configured class. The
77 constructor of this class should then register "callbacks" with the daemon,
78 using the appropriate static functions in B<Collectd>,
79 see L<"CALLING API FUNCTIONS"> below. To register a callback, the object being
80 passed to one of the register functions must implement an appropriate
81 interface, which are all in the B<org.collectd.api> namespace.
83 A constructor may register any number of these callbacks, even none. An object
84 without callback methods is never actively called by collectd, but may still
85 call the exported API functions. One could, for example, start a new thread in
86 the constructor and dispatch (submit to the daemon) values asynchronously,
87 whenever one is available.
89 Each callback method is now explained in more detail:
91 =head2 config callback
93 Interface: B<org.collectd.api.CollectdConfigInterface>
95 Signature: I<int> B<config> (I<OConfigItem> ci)
97 This method is passed a B<OConfigItem> object, if both, method and
98 configuration, are available. B<OConfigItem> is the root of a tree representing
99 the configuration for this plugin. The root itself is the representation of the
100 B<E<lt>PluginE<nbsp>/E<gt>> block, so in next to all cases the children of the
101 root are the first interesting objects.
103 To signal success, this method has to return zero. Anything else will be
104 considered an error condition and the plugin will be disabled entirely.
106 =head2 init callback
108 Interface: B<org.collectd.api.CollectdInitInterface>
110 Signature: I<int> B<init> ()
112 This method is called after the configuration has been handled. It is
113 supposed to set up the plugin. e.E<nbsp>g. start threads, open connections, or
114 check if can do anything useful at all.
116 To signal success, this method has to return zero. Anything else will be
117 considered an error condition and the plugin will be disabled entirely.
119 =head2 read callback
121 Interface: B<org.collectd.api.CollectdReadInterface>
123 Signature: I<int> B<read> ()
125 This method is called periodically and is supposed to gather statistics in
126 whatever fashion. These statistics are represented as a B<ValueList> object and
127 sent to the daemon using B<dispatchValues>, see L<"CALLING API FUNCTIONS">
128 below.
130 To signal success, this method has to return zero. Anything else will be
131 considered an error condition and cause an appropriate message to be logged.
132 Currently, returning non-zero does not have any other effects. In particular,
133 Java "read"-methods are not suspended for increasing intervals like C
134 "read"-functions.
136 =head2 write callback
138 Interface: B<org.collectd.api.CollectdWriteInterface>
140 Signature: I<int> B<write> (I<ValueList> vl)
142 This method is called whenever a value is dispatched to the daemon. The
143 corresponding C "write"-functions are passed a C<data_set_t>, so they can
144 decide which values are absolute values (gauge) and which are counter values.
145 To get the corresponding C<ListE<lt>DataSourceE<gt>>, call the B<getDataSource>
146 method of the B<ValueList> object.
148 To signal success, this method has to return zero. Anything else will be
149 considered an error condition and cause an appropriate message to be logged.
151 =head2 flush callback
153 Interface: B<org.collectd.api.CollectdFlushInterface>
155 Signature: I<int> B<flush> (I<int> timeout, I<String> identifier)
157 This method is called when the daemon received a flush command. This can either
158 be done using the C<USR1> signal (see L<collectd(1)>) or using the I<unixsock>
159 plugin (see L<collectd-unixsock(1)>).
161 If I<timeout> is greater than zero, only values older than this number of
162 seconds should be flushed. To signal that all values should be flushed
163 regardless of age, this argument is set to a negative number.
165 The I<identifier> specifies which value should be flushed. If it is not
166 possible to flush one specific value, flush all values. To signal that all
167 values should be flushed, this argument is set to I<null>.
169 To signal success, this method has to return zero. Anything else will be
170 considered an error condition and cause an appropriate message to be logged.
172 =head2 shutdown callback
174 Interface: B<org.collectd.api.CollectdShutdownInterface>
176 Signature: I<int> B<shutdown> ()
178 This method is called when the daemon is shutting down. You should not rely on
179 the destructor to clean up behind the object but use this function instead.
181 To signal success, this method has to return zero. Anything else will be
182 considered an error condition and cause an appropriate message to be logged.
184 =head2 log callback
186 Interface: B<org.collectd.api.CollectdLogInterface>
188 Signature: I<void> B<log> (I<int> severity, I<String> message)
190 This callback can be used to receive log messages from the daemon.
192 The argument I<severity> is one of:
194 =over 4
196 =item *
198 org.collectd.api.Collectd.LOG_ERR
200 =item *
202 org.collectd.api.Collectd.LOG_WARNING
204 =item *
206 org.collectd.api.Collectd.LOG_NOTICE
208 =item *
210 org.collectd.api.Collectd.LOG_INFO
212 =item *
214 org.collectd.api.Collectd.LOG_DEBUG
216 =back
218 The function does not return any value.
220 =head2 Example
222 This short example demonstrates how to register a read callback with the
223 daemon:
225   import org.collectd.api.Collectd;
226   import org.collectd.api.ValueList;
227   
228   import org.collectd.api.CollectdReadInterface;
229   
230   public class Foobar implements CollectdReadInterface
231   {
232     public Foobar ()
233     {
234       Collectd.registerRead ("Foobar", this);
235     }
236     
237     public int read ()
238     {
239       ValueList vl;
240       
241       /* Do something... */
242       
243       Collectd.dispatchValues (vl);
244     }
245   }
247 =head1 CALLING API FUNCTIONS
249 All collectd API functions that are available to Java plugins are implemented
250 as I<publicE<nbsp>static> functions of the B<org.collectd.api.Collectd> class.
251 This makes calling these functions pretty straight forward.
253 The following are the currently exported functions. For information on the
254 interfaces used, please see L<"REGISTERING CALLBACKS"> above.
256 =head2 registerConfig
258 Signature: I<int> B<registerConfig> (I<String> name,
259 I<CollectdConfigInterface> object);
261 Registers the B<config> function of I<object> with the daemon.
263 Returns zero upon success and non-zero when an error occurred.
265 =head2 registerInit
267 Signature: I<int> B<registerInit> (I<String> name,
268 I<CollectdInitInterface> object);
270 Registers the B<init> function of I<object> with the daemon.
272 Returns zero upon success and non-zero when an error occurred.
274 =head2 registerRead
276 Signature: I<int> B<registerRead> (I<String> name,
277 I<CollectdReadInterface> object)
279 Registers the B<read> function of I<object> with the daemon.
281 Returns zero upon success and non-zero when an error occurred.
283 =head2 registerWrite
285 Signature: I<int> B<registerWrite> (I<String> name,
286 I<CollectdWriteInterface> object)
288 Registers the B<write> function of I<object> with the daemon.
290 Returns zero upon success and non-zero when an error occurred.
292 =head2 registerFlush
294 Signature: I<int> B<registerFlush> (I<String> name,
295 I<CollectdFlushInterface> object)
297 Registers the B<flush> function of I<object> with the daemon.
299 Returns zero upon success and non-zero when an error occurred.
301 =head2 registerShutdown
303 Signature: I<int> B<registerShutdown> (I<String> name,
304 I<CollectdShutdownInterface> object);
306 Registers the B<shutdown> function of I<object> with the daemon.
308 Returns zero upon success and non-zero when an error occurred.
310 =head2 registerLog
312 Signature: I<int> B<registerLog> (I<String> name,
313 I<CollectdLogInterface> object);
315 Registers the B<log> function of I<object> with the daemon.
317 Returns zero upon success and non-zero when an error occurred.
319 =head2 dispatchValues
321 Signature: I<int> B<dispatchValues> (I<ValueList>)
323 Passes the values represented by the B<ValueList> object to the
324 C<plugin_dispatch_values> function of the daemon. The "data set" (or list of
325 "data sources") associated with the object are ignored, because
326 C<plugin_dispatch_values> will automatically lookup the required data set. It
327 is therefore absolutely okay to leave this blank.
329 Returns zero upon success or non-zero upon failure.
331 =head2 getDS
333 Signature: I<DataSet> B<getDS> (I<String>)
335 Returns the approrpate I<type> or B<null> if the type is not defined.
337 =head2 logError
339 Signature: I<void> B<logError> (I<String>)
341 Sends a log message with severity B<ERROR> to the daemon.
343 =head2 logWarning
345 Signature: I<void> B<logWarning> (I<String>)
347 Sends a log message with severity B<WARNING> to the daemon.
349 =head2 logNotice
351 Signature: I<void> B<logNotice> (I<String>)
353 Sends a log message with severity B<NOTICE> to the daemon.
355 =head2 logInfo
357 Signature: I<void> B<logInfo> (I<String>)
359 Sends a log message with severity B<INFO> to the daemon.
361 =head2 logDebug
363 Signature: I<void> B<logDebug> (I<String>)
365 Sends a log message with severity B<DEBUG> to the daemon.
367 =head1 SEE ALSO
369 L<collectd(1)>,
370 L<collectd.conf(5)>,
371 L<collectd-perl(5)>,
372 L<types.db(5)>
374 =head1 AUTHOR
376 Florian Forster E<lt>octoE<nbsp>atE<nbsp>verplant.orgE<gt>