Code

773130acc18e495f3f65bd757ae8219a9c5104e1
[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 =item B<org.collectd.api.Notification>
66 Corresponds to C<notification_t>, defined in F<src/plugin.h>.
68 =back
70 In the remainder of this document, we'll use the short form of these names, for
71 example B<ValueList>. In order to be able to use these abbreviated names, you
72 need to B<import> the classes.
74 The API functions that are available from Java are implemented as I<static>
75 functions of the B<org.collectd.api.Collectd> class.
76 See L<"CALLING API FUNCTIONS"> below for details.
78 =head1 REGISTERING CALLBACKS
80 When starting up, collectd creates an object of each configured class. The
81 constructor of this class should then register "callbacks" with the daemon,
82 using the appropriate static functions in B<Collectd>,
83 see L<"CALLING API FUNCTIONS"> below. To register a callback, the object being
84 passed to one of the register functions must implement an appropriate
85 interface, which are all in the B<org.collectd.api> namespace.
87 A constructor may register any number of these callbacks, even none. An object
88 without callback methods is never actively called by collectd, but may still
89 call the exported API functions. One could, for example, start a new thread in
90 the constructor and dispatch (submit to the daemon) values asynchronously,
91 whenever one is available.
93 Each callback method is now explained in more detail:
95 =head2 config callback
97 Interface: B<org.collectd.api.CollectdConfigInterface>
99 Signature: I<int> B<config> (I<OConfigItem> ci)
101 This method is passed a B<OConfigItem> object, if both, method and
102 configuration, are available. B<OConfigItem> is the root of a tree representing
103 the configuration for this plugin. The root itself is the representation of the
104 B<E<lt>PluginE<nbsp>/E<gt>> block, so in next to all cases the children of the
105 root are the first interesting objects.
107 To signal success, this method has to return zero. Anything else will be
108 considered an error condition and the plugin will be disabled entirely.
110 =head2 init callback
112 Interface: B<org.collectd.api.CollectdInitInterface>
114 Signature: I<int> B<init> ()
116 This method is called after the configuration has been handled. It is
117 supposed to set up the plugin. e.E<nbsp>g. start threads, open connections, or
118 check if can do anything useful at all.
120 To signal success, this method has to return zero. Anything else will be
121 considered an error condition and the plugin will be disabled entirely.
123 =head2 read callback
125 Interface: B<org.collectd.api.CollectdReadInterface>
127 Signature: I<int> B<read> ()
129 This method is called periodically and is supposed to gather statistics in
130 whatever fashion. These statistics are represented as a B<ValueList> object and
131 sent to the daemon using B<dispatchValues>, see L<"CALLING API FUNCTIONS">
132 below.
134 To signal success, this method has to return zero. Anything else will be
135 considered an error condition and cause an appropriate message to be logged.
136 Currently, returning non-zero does not have any other effects. In particular,
137 Java "read"-methods are not suspended for increasing intervals like C
138 "read"-functions.
140 =head2 write callback
142 Interface: B<org.collectd.api.CollectdWriteInterface>
144 Signature: I<int> B<write> (I<ValueList> vl)
146 This method is called whenever a value is dispatched to the daemon. The
147 corresponding C "write"-functions are passed a C<data_set_t>, so they can
148 decide which values are absolute values (gauge) and which are counter values.
149 To get the corresponding C<ListE<lt>DataSourceE<gt>>, call the B<getDataSource>
150 method of the B<ValueList> object.
152 To signal success, this method has to return zero. Anything else will be
153 considered an error condition and cause an appropriate message to be logged.
155 =head2 flush callback
157 Interface: B<org.collectd.api.CollectdFlushInterface>
159 Signature: I<int> B<flush> (I<int> timeout, I<String> identifier)
161 This method is called when the daemon received a flush command. This can either
162 be done using the C<USR1> signal (see L<collectd(1)>) or using the I<unixsock>
163 plugin (see L<collectd-unixsock(5)>).
165 If I<timeout> is greater than zero, only values older than this number of
166 seconds should be flushed. To signal that all values should be flushed
167 regardless of age, this argument is set to a negative number.
169 The I<identifier> specifies which value should be flushed. If it is not
170 possible to flush one specific value, flush all values. To signal that all
171 values should be flushed, this argument is set to I<null>.
173 To signal success, this method has to return zero. Anything else will be
174 considered an error condition and cause an appropriate message to be logged.
176 =head2 shutdown callback
178 Interface: B<org.collectd.api.CollectdShutdownInterface>
180 Signature: I<int> B<shutdown> ()
182 This method is called when the daemon is shutting down. You should not rely on
183 the destructor to clean up behind the object but use this function instead.
185 To signal success, this method has to return zero. Anything else will be
186 considered an error condition and cause an appropriate message to be logged.
188 =head2 log callback
190 Interface: B<org.collectd.api.CollectdLogInterface>
192 Signature: I<void> B<log> (I<int> severity, I<String> message)
194 This callback can be used to receive log messages from the daemon.
196 The argument I<severity> is one of:
198 =over 4
200 =item *
202 org.collectd.api.Collectd.LOG_ERR
204 =item *
206 org.collectd.api.Collectd.LOG_WARNING
208 =item *
210 org.collectd.api.Collectd.LOG_NOTICE
212 =item *
214 org.collectd.api.Collectd.LOG_INFO
216 =item *
218 org.collectd.api.Collectd.LOG_DEBUG
220 =back
222 The function does not return any value.
224 =head2 notification callback
226 Interface: B<org.collectd.api.CollectdNotificationInterface>
228 Signature: I<int> B<notification> (I<Notification> n)
230 This callback can be used to receive notifications from the daemon.
232 To signal success, this method has to return zero. Anything else will be
233 considered an error condition and cause an appropriate message to be logged.
235 =head2 Example
237 This short example demonstrates how to register a read callback with the
238 daemon:
240   import org.collectd.api.Collectd;
241   import org.collectd.api.ValueList;
242   
243   import org.collectd.api.CollectdReadInterface;
244   
245   public class Foobar implements CollectdReadInterface
246   {
247     public Foobar ()
248     {
249       Collectd.registerRead ("Foobar", this);
250     }
251     
252     public int read ()
253     {
254       ValueList vl;
255       
256       /* Do something... */
257       
258       Collectd.dispatchValues (vl);
259     }
260   }
262 =head1 CALLING API FUNCTIONS
264 All collectd API functions that are available to Java plugins are implemented
265 as I<publicE<nbsp>static> functions of the B<org.collectd.api.Collectd> class.
266 This makes calling these functions pretty straight forward.
268 The following are the currently exported functions. For information on the
269 interfaces used, please see L<"REGISTERING CALLBACKS"> above.
271 =head2 registerConfig
273 Signature: I<int> B<registerConfig> (I<String> name,
274 I<CollectdConfigInterface> object);
276 Registers the B<config> function of I<object> with the daemon.
278 Returns zero upon success and non-zero when an error occurred.
280 =head2 registerInit
282 Signature: I<int> B<registerInit> (I<String> name,
283 I<CollectdInitInterface> object);
285 Registers the B<init> function of I<object> with the daemon.
287 Returns zero upon success and non-zero when an error occurred.
289 =head2 registerRead
291 Signature: I<int> B<registerRead> (I<String> name,
292 I<CollectdReadInterface> object)
294 Registers the B<read> function of I<object> with the daemon.
296 Returns zero upon success and non-zero when an error occurred.
298 =head2 registerWrite
300 Signature: I<int> B<registerWrite> (I<String> name,
301 I<CollectdWriteInterface> object)
303 Registers the B<write> function of I<object> with the daemon.
305 Returns zero upon success and non-zero when an error occurred.
307 =head2 registerFlush
309 Signature: I<int> B<registerFlush> (I<String> name,
310 I<CollectdFlushInterface> object)
312 Registers the B<flush> function of I<object> with the daemon.
314 Returns zero upon success and non-zero when an error occurred.
316 =head2 registerShutdown
318 Signature: I<int> B<registerShutdown> (I<String> name,
319 I<CollectdShutdownInterface> object);
321 Registers the B<shutdown> function of I<object> with the daemon.
323 Returns zero upon success and non-zero when an error occurred.
325 =head2 registerLog
327 Signature: I<int> B<registerLog> (I<String> name,
328 I<CollectdLogInterface> object);
330 Registers the B<log> function of I<object> with the daemon.
332 Returns zero upon success and non-zero when an error occurred.
334 =head2 registerNotification
336 Signature: I<int> B<registerNotification> (I<String> name,
337 I<CollectdNotificationInterface> object);
339 Registers the B<notification> function of I<object> with the daemon.
341 Returns zero upon success and non-zero when an error occurred.
343 =head2 dispatchValues
345 Signature: I<int> B<dispatchValues> (I<ValueList>)
347 Passes the values represented by the B<ValueList> object to the
348 C<plugin_dispatch_values> function of the daemon. The "data set" (or list of
349 "data sources") associated with the object are ignored, because
350 C<plugin_dispatch_values> will automatically lookup the required data set. It
351 is therefore absolutely okay to leave this blank.
353 Returns zero upon success or non-zero upon failure.
355 =head2 getDS
357 Signature: I<DataSet> B<getDS> (I<String>)
359 Returns the approrpate I<type> or B<null> if the type is not defined.
361 =head2 logError
363 Signature: I<void> B<logError> (I<String>)
365 Sends a log message with severity B<ERROR> to the daemon.
367 =head2 logWarning
369 Signature: I<void> B<logWarning> (I<String>)
371 Sends a log message with severity B<WARNING> to the daemon.
373 =head2 logNotice
375 Signature: I<void> B<logNotice> (I<String>)
377 Sends a log message with severity B<NOTICE> to the daemon.
379 =head2 logInfo
381 Signature: I<void> B<logInfo> (I<String>)
383 Sends a log message with severity B<INFO> to the daemon.
385 =head2 logDebug
387 Signature: I<void> B<logDebug> (I<String>)
389 Sends a log message with severity B<DEBUG> to the daemon.
391 =head1 SEE ALSO
393 L<collectd(1)>,
394 L<collectd.conf(5)>,
395 L<collectd-perl(5)>,
396 L<types.db(5)>
398 =head1 AUTHOR
400 Florian Forster E<lt>octoE<nbsp>atE<nbsp>verplant.orgE<gt>