Merge branch 'collectd-4.8'
authorFlorian Forster <octo@leeloo.lan.home.verplant.org>
Wed, 9 Dec 2009 15:51:24 +0000 (16:51 +0100)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Wed, 9 Dec 2009 15:51:24 +0000 (16:51 +0100)
contrib/examples/MyPlugin.pm
src/protocols.c
src/utils_cmd_listval.c

index 13806ee..b1a8a6d 100644 (file)
@@ -40,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');
@@ -68,16 +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 (it is strongly recommended to use a type defined in the
-       # types.db file)
-       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.
index 73fe154..e90c1a4 100644 (file)
@@ -166,7 +166,7 @@ static int read_file (const char *path)
     if (key_fields_num != value_fields_num)
     {
       ERROR ("protocols plugin: Number of fields in keys and values lines "
-          "dont match: %i vs %i.",
+          "don't match: %i vs %i.",
           key_fields_num, value_fields_num);
       break;
     }
index bca83a9..072593f 100644 (file)
@@ -79,8 +79,14 @@ int handle_listval (FILE *fh, char *buffer)
   print_to_socket (fh, "%i Value%s found\n",
       (int) number, (number == 1) ? "" : "s");
   for (i = 0; i < number; i++)
+  {
     print_to_socket (fh, "%u %s\n", (unsigned int) times[i], names[i]);
+    sfree(names[i]);
+  }
 
+  sfree(names);
+  sfree(times);
+   
   return (0);
 } /* int handle_listval */