Merge branch 'collectd-4.0' into collectd-4.1
authorFlorian Forster <octo@leeloo.lan.home.verplant.org>
Fri, 12 Oct 2007 16:33:59 +0000 (18:33 +0200)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Fri, 12 Oct 2007 16:33:59 +0000 (18:33 +0200)
Conflicts:

src/rrdtool.c

contrib/examples/MyPlugin.pm [new file with mode: 0644]
contrib/examples/myplugin.c [new file with mode: 0644]
src/collectd.conf.pod
src/network.c
src/processes.c
src/rrdtool.c
src/unixsock.c
src/utils_ignorelist.c
src/utils_mount.c

diff --git a/contrib/examples/MyPlugin.pm b/contrib/examples/MyPlugin.pm
new file mode 100644 (file)
index 0000000..1b98d5b
--- /dev/null
@@ -0,0 +1,125 @@
+# /usr/share/doc/collectd/examples/MyPlugin.pm
+#
+# A Perl plugin template for collectd.
+#
+# Written by Sebastian Harl <sh@tokkee.org>
+#
+# This is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation; only version 2 of the License is applicable.
+
+# Notes:
+# - each of the functions below (and the corresponding plugin_register call)
+#   is optional
+
+package Collectd::Plugin::MyPlugin;
+
+use strict;
+use warnings;
+
+# data set definition:
+# see section "DATA TYPES" in collectd-perl(5) for details
+my $dataset =
+[
+       {
+               name => 'my_ds',
+               type => Collectd::DS_TYPE_GAUGE,
+               min  => 0,
+               max  => 65535,
+       },
+];
+
+# This code is executed after loading the plugin to register it with collectd.
+Collectd::plugin_register (Collectd::TYPE_LOG, 'myplugin', \&my_log);
+Collectd::plugin_register (Collectd::TYPE_DATASET, 'myplugin', $dataset);
+Collectd::plugin_register (Collectd::TYPE_INIT, 'myplugin', \&my_init);
+Collectd::plugin_register (Collectd::TYPE_READ, 'myplugin', \&my_read);
+Collectd::plugin_register (Collectd::TYPE_WRITE, 'myplugin', \&my_write);
+Collectd::plugin_register (Collectd::TYPE_SHUTDOWN, 'myplugin', \&my_shutdown);
+
+# For each of the functions below see collectd-perl(5) for details about
+# arguments and the like.
+
+# This function is called once upon startup to initialize the plugin.
+sub my_init
+{
+       # open sockets, initialize data structures, ...
+
+       # A false return value indicates an error and causes the plugin to be
+       # disabled.
+       return 1;
+} # my_init ()
+
+# This function is called in regular intervals to collectd the data.
+sub my_read
+{
+       # value list to dispatch to collectd:
+       # see section "DATA TYPES" in collectd-perl(5) for details
+       my $vl = {};
+
+       # 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
+       $vl->{'values'} = [ rand(65535) ];
+       $vl->{'plugin'} = 'myplugin';
+       # 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
+       Collectd::plugin_dispatch_values ('myplugin', $vl);
+
+       # A false return value indicates an error and the plugin will be skipped
+       # for an increasing amount of time.
+       return 1;
+} # my_read ()
+
+# This function is called after values have been dispatched to collectd.
+sub my_write
+{
+       my $type = shift;
+       my $ds   = shift;
+       my $vl   = shift;
+
+       if (scalar (@$ds) != scalar (@{$vl->{'values'}})) {
+               Collectd::plugin_log (Collectd::LOG_WARNING,
+                       "DS number does not match values length");
+               return;
+       }
+
+       for (my $i = 0; $i < scalar (@$ds); ++$i) {
+               # do the magic to output the data
+               print "$vl->{'host'}: $vl->{'plugin'}: ";
+
+               if (defined $vl->{'plugin_instance'}) {
+                       print "$vl->{'plugin_instance'}: ";
+               }
+
+               print "$type: ";
+
+               if (defined $vl->{'type_instance'}) {
+                       print "$vl->{'type_instance'}: ";
+               }
+
+               print "$vl->{'values'}->[$i]\n";
+       }
+       return 1;
+} # my_write()
+
+# This function is called before shutting down collectd.
+sub my_shutdown
+{
+       # close sockets, ...
+       return 1;
+} # my_shutdown ()
+
+# This function is called when plugin_log () has been used.
+sub my_log
+{
+       my $level = shift;
+       my $msg   = shift;
+
+       print "LOG: $level - $msg\n";
+       return 1;
+} # my_log ()
+
diff --git a/contrib/examples/myplugin.c b/contrib/examples/myplugin.c
new file mode 100644 (file)
index 0000000..fc7856b
--- /dev/null
@@ -0,0 +1,171 @@
+/*
+ * /usr/share/doc/collectd/examples/myplugin.c
+ *
+ * A plugin template for collectd.
+ *
+ * Written by Sebastian Harl <sh@tokkee.org>
+ *
+ * This is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free
+ * Software Foundation; only version 2 of the License is applicable.
+ */
+
+/*
+ * Notes:
+ * - plugins are executed in parallel, thus, thread-safe
+ *   functions need to be used
+ * - each of the functions below (except module_register)
+ *   is optional
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <string.h>
+
+#ifndef __USE_ISOC99 /* required for NAN */
+# define DISABLE_ISOC99 1
+# define __USE_ISOC99 1
+#endif /* !defined(__USE_ISOC99) */
+#include <math.h>
+#if DISABLE_ISOC99
+# undef DISABLE_ISOC99
+# undef __USE_ISOC99
+#endif /* DISABLE_ISOC99 */
+
+#include <collectd/collectd.h>
+#include <collectd/common.h>
+#include <collectd/plugin.h>
+
+/*
+ * data source definition:
+ * - name of the data source
+ * - type of the data source (DS_TYPE_GAUGE, DS_TYPE_COUNTER)
+ * - minimum allowed value
+ * - maximum allowed value
+ */
+static data_source_t dsrc[1] =
+{
+       { "my_ds", DS_TYPE_GAUGE, 0, NAN }
+};
+
+/*
+ * data set definition:
+ * - name of the data set
+ * - number of data sources
+ * - list of data sources
+ */
+static data_set_t ds =
+{
+       "myplugin", STATIC_ARRAY_SIZE (dsrc), dsrc
+};
+
+/*
+ * This function is called once upon startup to initialize the plugin.
+ */
+static int my_init (void)
+{
+       /* open sockets, initialize data structures, ... */
+
+       /* A return value != 0 indicates an error and causes the plugin to be
+          disabled. */
+    return 0;
+} /* static int my_init (void) */
+
+/*
+ * This function is called in regular intervalls to collect the data.
+ */
+static int my_read (void)
+{
+       value_t values[1]; /* the size of this list should equal the number of
+                                                 data sources */
+       value_list_t vl = VALUE_LIST_INIT;
+
+       /* do the magic to read the data */
+       values[0].gauge = random ();
+
+       vl.values     = values;
+       vl.values_len = 1;
+       vl.time       = time (NULL);
+       strcpy (vl.host, hostname_g);
+       strcpy (vl.plugin, "myplugin");
+       /* optionally set vl.plugin_instance and vl.type_instance to reasonable
+        * values (default: "") */
+
+       /* 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);
+
+       /* A return value != 0 indicates an error and the plugin will be skipped
+        * for an increasing amount of time. */
+    return 0;
+} /* static int my_read (void) */
+
+/*
+ * This function is called after values have been dispatched to collectd.
+ */
+static int my_write (const data_set_t *ds, const value_list_t *vl)
+{
+       char name[1024] = "";
+       int i = 0;
+
+       if (ds->ds_num != vl->values_len) {
+               plugin_log (LOG_WARNING, "DS number does not match values length");
+               return -1;
+       }
+
+       /* get the default base filename for the output file - depending on the
+        * provided values this will be something like
+        * <host>/<plugin>[-<plugin_type>]/<instance>[-<instance_type>] */
+       if (0 != format_name (name, 1024, vl->host, vl->plugin,
+                       vl->plugin_instance, ds->type, vl->type_instance))
+               return -1;
+
+       for (i = 0; i < ds->ds_num; ++i) {
+               /* do the magic to output the data */
+               printf ("%s (%s) at %i: ", name,
+                               (ds->ds->type == DS_TYPE_GAUGE) ? "GAUGE" : "COUNTER",
+                               (int)vl->time);
+
+               if (ds->ds->type == DS_TYPE_GAUGE)
+                       printf ("%f\n", vl->values[i].gauge);
+               else
+                       printf ("%lld\n", vl->values[i].counter);
+       }
+       return 0;
+} /* static int my_write (data_set_t *, value_list_t *) */
+
+/*
+ * This function is called when plugin_log () has been used.
+ */
+static void my_log (int severity, const char *msg)
+{
+       printf ("LOG: %i - %s\n", severity, msg);
+       return;
+} /* static void my_log (int, const char *) */
+
+/*
+ * This function is called before shutting down collectd.
+ */
+static int my_shutdown (void)
+{
+       /* close sockets, free data structures, ... */
+       return 0;
+} /* static int my_shutdown (void) */
+
+/*
+ * This function is called after loading the plugin to register it with
+ * collectd.
+ */
+void module_register (void)
+{
+       plugin_register_log ("myplugin", my_log);
+       plugin_register_data_set (&ds);
+       plugin_register_read ("myplugin", my_read);
+       plugin_register_init ("myplugin", my_init);
+       plugin_register_write ("myplugin", my_write);
+       plugin_register_shutdown ("myplugin", my_shutdown);
+    return;
+} /* void module_register (void) */
+
index 1485197..db87f9c 100644 (file)
@@ -163,7 +163,7 @@ installed and an "cpu governor" (that's a kernel module) is loaded.
 
 =item B<DataDir> I<Directory>
 
-Set the directory to store RRD-files under. Per default RRD-files are generated
+Set the directory to store CSV-files under. Per default CSV-files are generated
 beneath the daemon's working directory, i.E<nbsp>e. the B<BaseDir>.
 
 =back
@@ -394,7 +394,7 @@ TCP-Port to connect to. Defaults to B<411>.
 The C<mysql plugin> requires B<mysqlclient> to be installed. It connects to the
 database when started and keeps the connection up as long as possible. When the
 connection is interrupted for whatever reason it will try to re-connect. The
-plugin logs loud complaints in case anything goes wrong.
+plugin will complaint loudly in case anything goes wrong.
 
 This plugin issues C<SHOW STATUS> and evaluates C<Bytes_{received,sent}>,
 C<Com_*> and C<Handler_*> which correspond to F<mysql_octets.rrd>,
index b0f8303..c81d711 100644 (file)
@@ -1091,7 +1091,6 @@ static int add_to_buffer (char *buffer, int buffer_size,
                                        vl->host, strlen (vl->host)) != 0)
                        return (-1);
                strcpy (vl_def->host, vl->host);
-               DEBUG ("network plugin: add_to_buffer: host = %s", vl->host);
        }
 
        if (vl_def->time != vl->time)
@@ -1100,8 +1099,6 @@ static int add_to_buffer (char *buffer, int buffer_size,
                                        (uint64_t) vl->time))
                        return (-1);
                vl_def->time = vl->time;
-               DEBUG ("network plugin: add_to_buffer: time = %u",
-                               (unsigned int) vl->time);
        }
 
        if (vl_def->interval != vl->interval)
@@ -1120,8 +1117,6 @@ static int add_to_buffer (char *buffer, int buffer_size,
                                        vl->plugin, strlen (vl->plugin)) != 0)
                        return (-1);
                strcpy (vl_def->plugin, vl->plugin);
-               DEBUG ("network plugin: add_to_buffer: plugin = %s",
-                               vl->plugin);
        }
 
        if (strcmp (vl_def->plugin_instance, vl->plugin_instance) != 0)
@@ -1131,8 +1126,6 @@ static int add_to_buffer (char *buffer, int buffer_size,
                                        strlen (vl->plugin_instance)) != 0)
                        return (-1);
                strcpy (vl_def->plugin_instance, vl->plugin_instance);
-               DEBUG ("network plugin: add_to_buffer: plugin_instance = %s",
-                               vl->plugin_instance);
        }
 
        if (strcmp (type_def, ds->type) != 0)
@@ -1141,7 +1134,6 @@ static int add_to_buffer (char *buffer, int buffer_size,
                                        ds->type, strlen (ds->type)) != 0)
                        return (-1);
                strcpy (type_def, ds->type);
-               DEBUG ("network plugin: add_to_buffer: type = %s", ds->type);
        }
 
        if (strcmp (vl_def->type_instance, vl->type_instance) != 0)
@@ -1151,8 +1143,6 @@ static int add_to_buffer (char *buffer, int buffer_size,
                                        strlen (vl->type_instance)) != 0)
                        return (-1);
                strcpy (vl_def->type_instance, vl->type_instance);
-               DEBUG ("network plugin: add_to_buffer: type_instance = %s",
-                               vl->type_instance);
        }
        
        if (write_part_values (&buffer, &buffer_size, ds, vl) != 0)
@@ -1294,8 +1284,6 @@ static int network_config (const char *key, const char *val)
 
 static int network_shutdown (void)
 {
-       DEBUG ("Shutting down.");
-
        listen_loop++;
 
        if (listen_thread != (pthread_t) 0)
@@ -1305,7 +1293,8 @@ static int network_shutdown (void)
                listen_thread = (pthread_t) 0;
        }
 
-       listen_thread = 0;
+       if (send_buffer_fill > 0)
+               flush_buffer ();
 
        if (cache_tree != NULL)
        {
index 9d8bc01..22d369d 100644 (file)
@@ -603,8 +603,8 @@ int ps_read_process (int pid, procstat_t *ps, char *state)
        /* Leave the rest at zero if this is only a zombi */
        if (ps->num_proc == 0)
        {
-               DEBUG ("This is only a zombi: pid = %i; name = %s;",
-                               pid, ps->name);
+               DEBUG ("processes plugin: This is only a zombi: pid = %i; "
+                               "name = %s;", pid, ps->name);
                return (0);
        }
 
index 7002dcf..77d8716 100644 (file)
@@ -714,7 +714,7 @@ static void rrd_cache_flush (int timeout)
        avl_iterator_t *iter;
        int i;
 
-       DEBUG ("Flushing cache, timeout = %i", timeout);
+       DEBUG ("rrdtool plugin: Flushing cache, timeout = %i", timeout);
 
        now = time (NULL);
 
@@ -757,7 +757,7 @@ static void rrd_cache_flush (int timeout)
        {
                if (avl_remove (cache, keys[i], (void *) &key, (void *) &rc) != 0)
                {
-                       DEBUG ("avl_remove (%s) failed.", keys[i]);
+                       DEBUG ("rrdtool plugin: avl_remove (%s) failed.", keys[i]);
                        continue;
                }
 
@@ -770,7 +770,6 @@ static void rrd_cache_flush (int timeout)
        } /* for (i = 0..keys_num) */
 
        free (keys);
-       DEBUG ("Flushed %i value(s)", keys_num);
 
        cache_flush_last = now;
 } /* void rrd_cache_flush */
index 6abbfef..43e29c2 100644 (file)
@@ -623,7 +623,7 @@ static void *us_server_thread (void *arg)
 
        while (loop != 0)
        {
-               DEBUG ("Calling accept..");
+               DEBUG ("unixsock plugin: Calling accept..");
                status = accept (sock_fd, NULL, NULL);
                if (status < 0)
                {
index d2546aa..bf39597 100644 (file)
@@ -240,8 +240,6 @@ void ignorelist_free (ignorelist_t *il)
        ignorelist_item_t *this;
        ignorelist_item_t *next;
 
-       DEBUG ("(il = 0x%p)", (void *) il);
-
        if (il == NULL)
                return;
 
index 67d2e33..efaa92f 100644 (file)
@@ -334,7 +334,7 @@ get_spec_by_uuid(const char *s)
        return get_spec_by_x(UUID, uuid);
 
        bad_uuid:
-               DEBUG("Found an invalid UUID: %s", s);
+               DEBUG("utils_mount: Found an invalid UUID: %s", s);
        return NULL;
 }
 
@@ -353,12 +353,12 @@ static char *get_device_name(const char *optstr)
        }
        else if (strncmp (optstr, "UUID=", 5) == 0)
        {
-               DEBUG ("TODO: check UUID= code!");
+               DEBUG ("utils_mount: TODO: check UUID= code!");
                rc = get_spec_by_uuid (optstr + 5);
        }
        else if (strncmp (optstr, "LABEL=", 6) == 0)
        {
-               DEBUG ("TODO: check LABEL= code!");
+               DEBUG ("utils_mount: TODO: check LABEL= code!");
                rc = get_spec_by_volume_label (optstr + 6);
        }
        else
@@ -368,7 +368,7 @@ static char *get_device_name(const char *optstr)
 
        if(!rc)
        {
-               DEBUG ("Error checking device name: optstr = %s", optstr);
+               DEBUG ("utils_mount: Error checking device name: optstr = %s", optstr);
        }
        return rc;
 }
@@ -384,7 +384,7 @@ static cu_mount_t *cu_mount_listmntent (void)
        struct tabmntent *mntlist;
        if(listmntent(&mntlist, COLLECTD_MNTTAB, NULL, NULL) < 0) {
                char errbuf[1024];
-               DEBUG("calling listmntent() failed: %s",
+               DEBUG("utils_mount: calling listmntent() failed: %s",
                                sstrerror (errno, errbuf, sizeof (errbuf)));
        }
 
@@ -396,7 +396,7 @@ static cu_mount_t *cu_mount_listmntent (void)
                if(loop == NULL) {   /* no loop= mount */
                        device = get_device_name(mnt->mnt_fsname);
                        if(device == NULL) {
-                               DEBUG("can't get devicename for fs (%s) %s (%s)"
+                               DEBUG("utils_mount: can't get devicename for fs (%s) %s (%s)"
                                        ": ignored", mnt->mnt_type,
                                        mnt->mnt_dir, mnt->mnt_fsname);
                                continue;
@@ -455,7 +455,7 @@ static cu_mount_t *cu_mount_getfsstat (void)
        if ((bufsize = CMD_STATFS (NULL, 0, FLAGS_STATFS)) < 1)
        {
                char errbuf[1024];
-               DEBUG ("getv?fsstat failed: %s",
+               DEBUG ("utils_mount: getv?fsstat failed: %s",
                                sstrerror (errno, errbuf, sizeof (errbuf)));
                return (NULL);
        }
@@ -470,7 +470,7 @@ static cu_mount_t *cu_mount_getfsstat (void)
        if ((num = CMD_STATFS (buf, bufsize * sizeof (STRUCT_STATFS), FLAGS_STATFS)) < 1)
        {
                char errbuf[1024];
-               DEBUG ("getv?fsstat failed: %s",
+               DEBUG ("utils_mount: getv?fsstat failed: %s",
                                sstrerror (errno, errbuf, sizeof (errbuf)));
                free (buf);
                return (NULL);
@@ -520,7 +520,7 @@ static cu_mount_t *cu_mount_gen_getmntent (void)
        cu_mount_t *last  = NULL;
        cu_mount_t *new   = NULL;
 
-       DEBUG ("(void); COLLECTD_MNTTAB = %s", COLLECTD_MNTTAB);
+       DEBUG ("utils_mount: (void); COLLECTD_MNTTAB = %s", COLLECTD_MNTTAB);
 
        if ((fp = fopen (COLLECTD_MNTTAB, "r")) == NULL)
        {
@@ -577,7 +577,7 @@ static cu_mount_t *cu_mount_getmntent (void)
        cu_mount_t *last  = NULL;
        cu_mount_t *new   = NULL;
 
-       DEBUG ("(void); COLLECTD_MNTTAB = %s", COLLECTD_MNTTAB);
+       DEBUG ("utils_mount: (void); COLLECTD_MNTTAB = %s", COLLECTD_MNTTAB);
 
        if ((fp = setmntent (COLLECTD_MNTTAB, "r")) == NULL)
        {
@@ -601,7 +601,7 @@ static cu_mount_t *cu_mount_getmntent (void)
                new->device      = get_device_name (new->options);
                new->next        = NULL;
 
-               DEBUG ("new = {dir = %s, spec_device = %s, type = %s, options = %s, device = %s}",
+               DEBUG ("utils_mount: new = {dir = %s, spec_device = %s, type = %s, options = %s, device = %s}",
                                new->dir, new->spec_device, new->type, new->options, new->device);
 
                /* Append to list */
@@ -619,7 +619,7 @@ static cu_mount_t *cu_mount_getmntent (void)
 
        endmntent (fp);
 
-       DEBUG ("return (0x%p)", (void *) first);
+       DEBUG ("utils_mount: return (0x%p)", (void *) first);
 
        return (first);
 }
@@ -682,8 +682,6 @@ void cu_mount_freelist (cu_mount_t *list)
        cu_mount_t *this;
        cu_mount_t *next;
 
-       DEBUG ("(list = 0x%p)", (void *) list);
-
        for (this = list; this != NULL; this = next)
        {
                next = this->next;