Code

Merge remote-tracking branch 'github/pr/387'
[collectd.git] / src / collectd-java.pod
1 =encoding UTF-8
3 =head1 NAME
5 collectd-java - Documentation of collectd's "java plugin"
7 =head1 SYNOPSIS
9  LoadPlugin "java"
10  <Plugin "java">
11    JVMArg "-verbose:jni"
12    JVMArg "-Djava.class.path=/opt/collectd/lib/collectd/bindings/java"
13    
14    LoadPlugin "org.collectd.java.Foobar"
15    <Plugin "org.collectd.java.Foobar">
16      # To be parsed by the plugin
17    </Plugin>
18  </Plugin>
20 =head1 DESCRIPTION
22 The I<Java> plugin embeds a I<Java Virtual Machine> (JVM) into I<collectd> and
23 provides a Java interface to part of collectd's API. This makes it possible to
24 write additions to the daemon in Java.
26 This plugin is similar in nature to, but shares no code with, the I<Perl>
27 plugin by Sebastian Harl, see L<collectd-perl(5)> for details.
29 =head1 CONFIGURATION
31 A short outline of this plugin's configuration can be seen in L<"SYNOPSIS">
32 above. For a complete list of all configuration options and their semantics
33 please read L<collectd.conf(5)/Plugin C<java>>.
35 =head1 OVERVIEW
37 When writing additions for collectd in Java, the underlying C base is mostly
38 hidden from you. All complex data types are converted to their Java counterparts
39 before they're passed to your functions. These Java classes reside in the
40 I<org.collectd.api> namespace.
42 The I<Java> plugin will create one object of each class configured with the
43 B<LoadPlugin> option. The constructor of this class can then register "callback
44 methods", i.E<nbsp>e. methods that will be called by the daemon when
45 appropriate.
47 The available classes are:
49 =over 4
51 =item B<org.collectd.api.Collectd>
53 All API functions exported to Java are implemented as static functions of this
54 class. See L<"EXPORTED API FUNCTIONS"> below.
56 =item B<org.collectd.api.OConfigValue>
58 Corresponds to C<oconfig_value_t>, defined in F<src/liboconfig/oconfig.h>.
60 =item B<org.collectd.api.OConfigItem>
62 Corresponds to C<oconfig_item_t>, defined in F<src/liboconfig/oconfig.h>.
64 =item B<org.collectd.api.DataSource>
66 Corresponds to C<data_source_t>, defined in F<src/plugin.h>.
68 =item B<org.collectd.api.DataSet>
70 Corresponds to C<data_set_t>, defined in F<src/plugin.h>.
72 =item B<org.collectd.api.ValueList>
74 Corresponds to C<value_list_t>, defined in F<src/plugin.h>.
76 =item B<org.collectd.api.Notification>
78 Corresponds to C<notification_t>, defined in F<src/plugin.h>.
80 =back
82 In the remainder of this document, we'll use the short form of these names, for
83 example B<ValueList>. In order to be able to use these abbreviated names, you
84 need to B<import> the classes.
86 =head1 EXPORTED API FUNCTIONS
88 All collectd API functions that are available to Java plugins are implemented
89 as I<publicE<nbsp>static> functions of the B<Collectd> class. This makes
90 calling these functions pretty straight forward. For example, to send an error
91 message to the daemon, you'd do something like this:
93   Collectd.logError ("That wasn't chicken!");
95 The following are the currently exported functions.
97 =head2 registerConfig
99 Signature: I<int> B<registerConfig> (I<String> name,
100 I<CollectdConfigInterface> object);
102 Registers the B<config> function of I<object> with the daemon.
104 Returns zero upon success and non-zero when an error occurred.
106 See L<"config callback"> below.
108 =head2 registerInit
110 Signature: I<int> B<registerInit> (I<String> name,
111 I<CollectdInitInterface> object);
113 Registers the B<init> function of I<object> with the daemon.
115 Returns zero upon success and non-zero when an error occurred.
117 See L<"init callback"> below.
119 =head2 registerRead
121 Signature: I<int> B<registerRead> (I<String> name,
122 I<CollectdReadInterface> object)
124 Registers the B<read> function of I<object> with the daemon.
126 Returns zero upon success and non-zero when an error occurred.
128 See L<"read callback"> below.
130 =head2 registerWrite
132 Signature: I<int> B<registerWrite> (I<String> name,
133 I<CollectdWriteInterface> object)
135 Registers the B<write> function of I<object> with the daemon.
137 Returns zero upon success and non-zero when an error occurred.
139 See L<"write callback"> below.
141 =head2 registerFlush
143 Signature: I<int> B<registerFlush> (I<String> name,
144 I<CollectdFlushInterface> object)
146 Registers the B<flush> function of I<object> with the daemon.
148 Returns zero upon success and non-zero when an error occurred.
150 See L<"flush callback"> below.
152 =head2 registerShutdown
154 Signature: I<int> B<registerShutdown> (I<String> name,
155 I<CollectdShutdownInterface> object);
157 Registers the B<shutdown> function of I<object> with the daemon.
159 Returns zero upon success and non-zero when an error occurred.
161 See L<"shutdown callback"> below.
163 =head2 registerLog
165 Signature: I<int> B<registerLog> (I<String> name,
166 I<CollectdLogInterface> object);
168 Registers the B<log> function of I<object> with the daemon.
170 Returns zero upon success and non-zero when an error occurred.
172 See L<"log callback"> below.
174 =head2 registerNotification
176 Signature: I<int> B<registerNotification> (I<String> name,
177 I<CollectdNotificationInterface> object);
179 Registers the B<notification> function of I<object> with the daemon.
181 Returns zero upon success and non-zero when an error occurred.
183 See L<"notification callback"> below.
185 =head2 registerMatch
187 Signature: I<int> B<registerMatch> (I<String> name,
188 I<CollectdMatchFactoryInterface> object);
190 Registers the B<createMatch> function of I<object> with the daemon.
192 Returns zero upon success and non-zero when an error occurred.
194 See L<"match callback"> below.
196 =head2 registerTarget
198 Signature: I<int> B<registerTarget> (I<String> name,
199 I<CollectdTargetFactoryInterface> object);
201 Registers the B<createTarget> function of I<object> with the daemon.
203 Returns zero upon success and non-zero when an error occurred.
205 See L<"target callback"> below.
207 =head2 dispatchValues
209 Signature: I<int> B<dispatchValues> (I<ValueList>)
211 Passes the values represented by the B<ValueList> object to the
212 C<plugin_dispatch_values> function of the daemon. The "data set" (or list of
213 "data sources") associated with the object are ignored, because
214 C<plugin_dispatch_values> will automatically lookup the required data set. It
215 is therefore absolutely okay to leave this blank.
217 Returns zero upon success or non-zero upon failure.
219 =head2 getDS
221 Signature: I<DataSet> B<getDS> (I<String>)
223 Returns the appropriate I<type> or B<null> if the type is not defined.
225 =head2 logError
227 Signature: I<void> B<logError> (I<String>)
229 Sends a log message with severity B<ERROR> to the daemon.
231 =head2 logWarning
233 Signature: I<void> B<logWarning> (I<String>)
235 Sends a log message with severity B<WARNING> to the daemon.
237 =head2 logNotice
239 Signature: I<void> B<logNotice> (I<String>)
241 Sends a log message with severity B<NOTICE> to the daemon.
243 =head2 logInfo
245 Signature: I<void> B<logInfo> (I<String>)
247 Sends a log message with severity B<INFO> to the daemon.
249 =head2 logDebug
251 Signature: I<void> B<logDebug> (I<String>)
253 Sends a log message with severity B<DEBUG> to the daemon.
255 =head1 REGISTERING CALLBACKS
257 When starting up, collectd creates an object of each configured class. The
258 constructor of this class should then register "callbacks" with the daemon,
259 using the appropriate static functions in B<Collectd>,
260 see L<"EXPORTED API FUNCTIONS"> above. To register a callback, the object being
261 passed to one of the register functions must implement an appropriate
262 interface, which are all in the B<org.collectd.api> namespace.
264 A constructor may register any number of these callbacks, even none. An object
265 without callback methods is never actively called by collectd, but may still
266 call the exported API functions. One could, for example, start a new thread in
267 the constructor and dispatch (submit to the daemon) values asynchronously,
268 whenever one is available.
270 Each callback method is now explained in more detail:
272 =head2 config callback
274 Interface: B<org.collectd.api.CollectdConfigInterface>
276 Signature: I<int> B<config> (I<OConfigItem> ci)
278 This method is passed a B<OConfigItem> object, if both, method and
279 configuration, are available. B<OConfigItem> is the root of a tree representing
280 the configuration for this plugin. The root itself is the representation of the
281 B<E<lt>PluginE<nbsp>/E<gt>> block, so in next to all cases the children of the
282 root are the first interesting objects.
284 To signal success, this method has to return zero. Anything else will be
285 considered an error condition and the plugin will be disabled entirely.
287 See L<"registerConfig"> above.
289 =head2 init callback
291 Interface: B<org.collectd.api.CollectdInitInterface>
293 Signature: I<int> B<init> ()
295 This method is called after the configuration has been handled. It is
296 supposed to set up the plugin. e.E<nbsp>g. start threads, open connections, or
297 check if can do anything useful at all.
299 To signal success, this method has to return zero. Anything else will be
300 considered an error condition and the plugin will be disabled entirely.
302 See L<"registerInit"> above.
304 =head2 read callback
306 Interface: B<org.collectd.api.CollectdReadInterface>
308 Signature: I<int> B<read> ()
310 This method is called periodically and is supposed to gather statistics in
311 whatever fashion. These statistics are represented as a B<ValueList> object and
312 sent to the daemon using L<dispatchValues|"dispatchValues">.
314 To signal success, this method has to return zero. Anything else will be
315 considered an error condition and cause an appropriate message to be logged.
316 Currently, returning non-zero does not have any other effects. In particular,
317 Java "read"-methods are not suspended for increasing intervals like C
318 "read"-functions.
320 See L<"registerRead"> above.
322 =head2 write callback
324 Interface: B<org.collectd.api.CollectdWriteInterface>
326 Signature: I<int> B<write> (I<ValueList> vl)
328 This method is called whenever a value is dispatched to the daemon. The
329 corresponding C "write"-functions are passed a C<data_set_t>, so they can
330 decide which values are absolute values (gauge) and which are counter values.
331 To get the corresponding C<ListE<lt>DataSourceE<gt>>, call the B<getDataSource>
332 method of the B<ValueList> object.
334 To signal success, this method has to return zero. Anything else will be
335 considered an error condition and cause an appropriate message to be logged.
337 See L<"registerWrite"> above.
339 =head2 flush callback
341 Interface: B<org.collectd.api.CollectdFlushInterface>
343 Signature: I<int> B<flush> (I<int> timeout, I<String> identifier)
345 This method is called when the daemon received a flush command. This can either
346 be done using the C<USR1> signal (see L<collectd(1)>) or using the I<unixsock>
347 plugin (see L<collectd-unixsock(5)>).
349 If I<timeout> is greater than zero, only values older than this number of
350 seconds should be flushed. To signal that all values should be flushed
351 regardless of age, this argument is set to a negative number.
353 The I<identifier> specifies which value should be flushed. If it is not
354 possible to flush one specific value, flush all values. To signal that all
355 values should be flushed, this argument is set to I<null>.
357 To signal success, this method has to return zero. Anything else will be
358 considered an error condition and cause an appropriate message to be logged.
360 See L<"registerFlush"> above.
362 =head2 shutdown callback
364 Interface: B<org.collectd.api.CollectdShutdownInterface>
366 Signature: I<int> B<shutdown> ()
368 This method is called when the daemon is shutting down. You should not rely on
369 the destructor to clean up behind the object but use this function instead.
371 To signal success, this method has to return zero. Anything else will be
372 considered an error condition and cause an appropriate message to be logged.
374 See L<"registerShutdown"> above.
376 =head2 log callback
378 Interface: B<org.collectd.api.CollectdLogInterface>
380 Signature: I<void> B<log> (I<int> severity, I<String> message)
382 This callback can be used to receive log messages from the daemon.
384 The argument I<severity> is one of:
386 =over 4
388 =item *
390 org.collectd.api.Collectd.LOG_ERR
392 =item *
394 org.collectd.api.Collectd.LOG_WARNING
396 =item *
398 org.collectd.api.Collectd.LOG_NOTICE
400 =item *
402 org.collectd.api.Collectd.LOG_INFO
404 =item *
406 org.collectd.api.Collectd.LOG_DEBUG
408 =back
410 The function does not return any value.
412 See L<"registerLog"> above.
414 =head2 notification callback
416 Interface: B<org.collectd.api.CollectdNotificationInterface>
418 Signature: I<int> B<notification> (I<Notification> n)
420 This callback can be used to receive notifications from the daemon.
422 To signal success, this method has to return zero. Anything else will be
423 considered an error condition and cause an appropriate message to be logged.
425 See L<"registerNotification"> above.
427 =head2 match callback
429 The match (and target, see L<"target callback"> below) callbacks work a bit
430 different from the other callbacks above: You don't register a match callback
431 with the daemon directly, but you register a function which, when called,
432 creates an appropriate object. The object creating the "match" objects is
433 called "match factory".
435 See L<"registerMatch"> above.
437 =head3 Factory object
439 Interface: B<org.collectd.api.CollectdMatchFactoryInterface>
441 Signature: I<CollectdMatchInterface> B<createMatch>
442 (I<OConfigItem> ci);
444 Called by the daemon to create "match" objects.
446 Returns: A new object which implements the B<CollectdMatchInterface> interface.
448 =head3 Match object
450 Interface: B<org.collectd.api.CollectdMatchInterface>
452 Signature: I<int> B<match> (I<DataSet> ds, I<ValueList> vl);
454 Called when processing a chain to determine whether or not a I<ValueList>
455 matches. How values are matches is up to the implementing class.
457 Has to return one of:
459 =over 4
461 =item *
463 B<Collectd.FC_MATCH_NO_MATCH>
465 =item *
467 B<Collectd.FC_MATCH_MATCHES>
469 =back
471 =head2 target callback
473 The target (and match, see L<"match callback"> above) callbacks work a bit
474 different from the other callbacks above: You don't register a target callback
475 with the daemon directly, but you register a function which, when called,
476 creates an appropriate object. The object creating the "target" objects is
477 called "target factory".
479 See L<"registerTarget"> above.
481 =head3 Factory object
483 Interface: B<org.collectd.api.CollectdTargetFactoryInterface>
485 Signature: I<CollectdTargetInterface> B<createTarget>
486 (I<OConfigItem> ci);
488 Called by the daemon to create "target" objects.
490 Returns: A new object which implements the B<CollectdTargetInterface>
491 interface.
493 =head3 Target object
495 Interface: B<org.collectd.api.CollectdTargetInterface>
497 Signature: I<int> B<invoke> (I<DataSet> ds, I<ValueList> vl);
499 Called when processing a chain to perform some action. The action performed is
500 up to the implementing class.
502 Has to return one of:
504 =over 4
506 =item *
508 B<Collectd.FC_TARGET_CONTINUE>
510 =item *
512 B<Collectd.FC_TARGET_STOP>
514 =item *
516 B<Collectd.FC_TARGET_RETURN>
518 =back
520 =head1 EXAMPLE
522 This short example demonstrates how to register a read callback with the
523 daemon:
525   import org.collectd.api.Collectd;
526   import org.collectd.api.ValueList;
527   
528   import org.collectd.api.CollectdReadInterface;
529   
530   public class Foobar implements CollectdReadInterface
531   {
532     public Foobar ()
533     {
534       Collectd.registerRead ("Foobar", this);
535     }
536     
537     public int read ()
538     {
539       ValueList vl;
540       
541       /* Do something... */
542       
543       Collectd.dispatchValues (vl);
544     }
545   }
547 =head1 PLUGINS
549 The following plugins are implemented in I<Java>. Both, the B<LoadPlugin>
550 option and the B<Plugin> block must be inside the
551 B<E<lt>PluginE<nbsp>javaE<gt>> block (see above).
553 =head2 GenericJMX plugin
555 The GenericJMX plugin reads I<Managed Beans> (MBeans) from an I<MBeanServer>
556 using JMX. JMX is a generic framework to provide and query various management
557 information. The interface is used by Java processes to provide internal
558 statistics as well as by the I<Java Virtual Machine> (JVM) to provide
559 information about the memory used, threads and so on. 
561 The configuration of the I<GenericJMX plugin> consists of two blocks: I<MBean>
562 blocks that define a mapping of MBean attributes to the “types” used by
563 I<collectd>, and I<Connection> blocks which define the parameters needed to
564 connect to an I<MBeanServer> and what data to collect. The configuration of the
565 I<SNMP plugin> is similar in nature, in case you know it.
567 =head3   MBean blocks
569 I<MBean> blocks specify what data is retrieved from I<MBeans> and how that data
570 is mapped on the I<collectd> data types. The block requires one string
571 argument, a name. This name is used in the I<Connection> blocks (see below) to
572 refer to a specific I<MBean> block. Therefore, the names must be unique.
574 The following options are recognized within I<MBean> blocks: 
576 =over 4
578 =item B<ObjectName> I<pattern>
580 Sets the pattern which is used to retrieve I<MBeans> from the I<MBeanServer>.
581 If more than one MBean is returned you should use the B<InstanceFrom> option
582 (see below) to make the identifiers unique.
584 See also:
585 L<http://java.sun.com/javase/6/docs/api/javax/management/ObjectName.html>
587 =item B<InstancePrefix> I<prefix>
589 Prefixes the generated I<plugin instance> with I<prefix>. I<(optional)>
591 =item B<InstanceFrom> I<property>
593 The I<object names> used by JMX to identify I<MBeans> include so called
594 I<“properties”> which are basically key-value-pairs. If the given object name
595 is not unique and multiple MBeans are returned, the values of those properties
596 usually differ. You can use this option to build the I<plugin instance> from
597 the appropriate property values. This option is optional and may be repeated to
598 generate the I<plugin instance> from multiple property values. 
600 =item B<E<lt>value /E<gt>> blocks
602 The I<value> blocks map one or more attributes of an I<MBean> to a value list
603 in I<collectd>. There must be at least one Value block within each I<MBean>
604 block.
606 =over 4
608 =item B<Type> type
610 Sets the data set used within I<collectd> to handle the values of the I<MBean>
611 attribute.
613 =item B<InstancePrefix> I<prefix>
615 Works like the option of the same name directly beneath the I<MBean> block, but
616 sets the type instance instead. I<(optional)>
618 =item B<InstanceFrom> I<prefix>
620 Works like the option of the same name directly beneath the I<MBean> block, but
621 sets the type instance instead. I<(optional)>
623 =item B<Table> B<true>|B<false>
625 Set this to true if the returned attribute is a I<composite type>. If set to
626 true, the keys within the I<composite type> is appended to the
627 I<type instance>.
629 =item B<Attribute> I<path>
631 Sets the name of the attribute from which to read the value. You can access the
632 keys of composite types by using a dot to concatenate the key name to the
633 attribute name. For example: “attrib0.key42”. If B<Table> is set to B<true>
634 I<path> must point to a I<composite type>, otherwise it must point to a numeric
635 type. 
637 =back
639 =back
641 =head3 Connection blocks
643 Connection blocks specify I<how> to connect to an I<MBeanServer> and what data
644 to retrieve. The following configuration options are available:
646 =over 4
648 =item B<Host> I<name>
650 Host name used when dispatching the values to I<collectd>. The option sets this
651 field only, it is I<not> used to connect to anything and doesn't need to be a
652 real, resolvable name.
654 =item B<ServiceURL> I<URL>
656 Specifies how the I<MBeanServer> can be reached. Any string accepted by the
657 I<JMXServiceURL> is valid.
659 See also:
660 L<http://java.sun.com/javase/6/docs/api/javax/management/remote/JMXServiceURL.html>
662 =item B<User> I<name>
664 Use I<name> to authenticate to the server. If not configured, “monitorRole”
665 will be used.
667 =item B<Password> I<password>
669 Use I<password> to authenticate to the server. If not given, unauthenticated
670 access is used.
672 =item B<InstancePrefix> I<prefix>
674 Prefixes the generated I<plugin instance> with I<prefix>. If a second
675 I<InstancePrefix> is specified in a referenced I<MBean> block, the prefix
676 specified in the I<Connection> block will appear at the beginning of the
677 I<plugin instance>, the prefix specified in the I<MBean> block will be appended
678 to it.
680 =item B<Collect> I<mbean_block_name>
682 Configures which of the I<MBean> blocks to use with this connection. May be
683 repeated to collect multiple I<MBeans> from this server. 
685 =back
687 =head1 SEE ALSO
689 L<collectd(1)>,
690 L<collectd.conf(5)>,
691 L<collectd-perl(5)>,
692 L<types.db(5)>
694 =head1 AUTHOR
696 Florian Forster E<lt>octoE<nbsp>atE<nbsp>verplant.orgE<gt>