X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=contrib%2Fexamples%2FMyPlugin.pm;h=b1a8a6d8ff3cb2487a1bd5c29de6f0c29336a6ee;hb=HEAD;hp=1a0247ff8e068cb7c1fd0d5b30169413f9977635;hpb=bc0a8f260e4e24bdf664c3dcff919b6f99bfe31d;p=collectd.git diff --git a/contrib/examples/MyPlugin.pm b/contrib/examples/MyPlugin.pm index 1a0247ff..b1a8a6d8 100644 --- a/contrib/examples/MyPlugin.pm +++ b/contrib/examples/MyPlugin.pm @@ -21,7 +21,12 @@ use Collectd qw( :all ); # data set definition: # see section "DATA TYPES" in collectd-perl(5) for details -# (take a look at the types.db file for a large list of predefined data-sets) +# +# NOTE: If you're defining a custom data-set, you have to make that known to +# any servers as well. Else, the server is not able to store values using the +# type defined by that data-set. +# It is strongly recommended to use one of the types and data-sets pre-defined +# in the types.db file. my $dataset = [ { @@ -35,7 +40,7 @@ my $dataset = # This code is executed after loading the plugin to register it with collectd. plugin_register (TYPE_LOG, 'myplugin', 'my_log'); plugin_register (TYPE_NOTIF, 'myplugin', 'my_notify'); -plugin_register (TYPE_DATASET, 'myplugin', $dataset); +plugin_register (TYPE_DATASET, 'mytype', $dataset); plugin_register (TYPE_INIT, 'myplugin', 'my_init'); plugin_register (TYPE_READ, 'myplugin', 'my_read'); plugin_register (TYPE_WRITE, 'myplugin', 'my_write'); @@ -63,15 +68,17 @@ sub my_read # do the magic to read the data: # the number of values has to match the number of data sources defined in - # the registered data set + # the registered data set. The type used here (in this example: + # "mytype") must be defined in the types.db, see types.db(5) for + # details, or registered as "TYPE_DATASET". $vl->{'values'} = [ rand(65535) ]; $vl->{'plugin'} = 'myplugin'; + $vl->{'type'} = 'mytype'; # any other elements are optional # dispatch the values to collectd which passes them on to all registered - # write functions - the first argument is used to lookup the data set - # definition - plugin_dispatch_values ('myplugin', $vl); + # write functions + plugin_dispatch_values ($vl); # A false return value indicates an error and the plugin will be skipped # for an increasing amount of time.