Merge branch 'pull/collectd-4' into collectd-4
authorFlorian Forster <octo@leeloo.lan.home.verplant.org>
Fri, 30 Mar 2007 20:04:16 +0000 (22:04 +0200)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Fri, 30 Mar 2007 20:04:16 +0000 (22:04 +0200)
src/collectd.conf.in
src/collectd.conf.pod
src/collectd.pod
src/csv.c
src/exec.c
src/unixsock.c

index 949e5ce..020bdeb 100644 (file)
 #      MaxConns 5
 #</Plugin>
 
+#<Plugin exec>
+#      Exec user "/path/to/exec"
+#</Plugin>
+
 #<Plugin hddtemp>
 #      Host "127.0.0.1"
 #      Port 7634
index 1e0f5a8..07a49cc 100644 (file)
@@ -210,6 +210,20 @@ at most B<16384> to prevent typos and dumb mistakes.
 
 =back
 
+=head2 Plugin C<exec>
+
+Please make sure to read L<collectd/"SPECIAL PLUGINS"> before using this
+plugin. It containes valueable information on when the executable is executed
+and the output that is expected from it.
+
+=over 4
+
+=item B<Exec> I<User> I<Executable>
+
+Execute the executable I<Executable> as user I<User>.
+
+=back
+
 =head2 Plugin C<hddtemp>
 
 =over 4
index 96c3fcd..bc65f57 100644 (file)
@@ -219,6 +219,39 @@ Successful spam checks (e.g. "BAYES_99", "SUBJECT_DRUG_GAP_C", ...):
 Each line is limited to 256 characters (including the newline character). 
 Longer lines will be ignored.
 
+=head2 exec
+
+The C<exec> plugin forks of an executable and reads back values that it writes
+to C<STDOUT>. The executable is forked kind of as L<init> does: It is forked
+once and not again until it exits. If it exited, it will be forked again after
+at most I<Interval> seconds. It is perfectly legal for the executable to run
+for a long time and continuously write values to C<STDOUT>.
+
+The forked executable is expected to print values to C<STDOUT>. The expected
+format is as follows:
+
+=over 4
+
+=item
+
+Each line beginning with a C<#> (hash mark) is ignored.
+
+=item
+
+Any other line must be of the form C<I<type>,I<type-instance>,I<value>>, where
+I<type> is either B<counter> or B<gauge>, I<type-instance> may not contain
+C<,> (comma), C</> (slash) and C<\0> (null byte) and I<value> is either an
+integer (if I<type> is B<counter>) or a floating-point number (if I<type> is
+B<gauge>).
+
+=back
+
+The values are always considered to be "fresh", i.E<nbsp>e. the time is set to
+"now".
+
+When collectd exits it sends a B<SIGTERM> to all still running
+child-processes upon which they have to quit.
+
 =head2 mysql
 
 Requires B<mysqlclient> to be installed. It connects to the database when
index e67a9ca..5d64fb8 100644 (file)
--- a/src/csv.c
+++ b/src/csv.c
@@ -201,7 +201,7 @@ static int csv_write (const data_set_t *ds, const value_list_t *vl)
        if (value_list_to_filename (filename, sizeof (filename), ds, vl) != 0)
                return (-1);
 
-       DEBUG ("filename = %s;", filename);
+       DEBUG ("csv plugin: csv_write: filename = %s;", filename);
 
        if (value_list_to_string (values, sizeof (values), ds, vl) != 0)
                return (-1);
index 82c7efa..5bddfc5 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <sys/types.h>
 #include <pwd.h>
+#include <signal.h>
 
 #include <pthread.h>
 
@@ -334,6 +335,7 @@ static void *exec_read_one (void *arg)
   pl->pid = 0;
 
   pthread_exit ((void *) 0);
+  return (NULL);
 } /* void *exec_read_one */
 
 static int exec_read (void)
@@ -356,6 +358,32 @@ static int exec_read (void)
   return (0);
 } /* int exec_read */
 
+static int exec_shutdown (void)
+{
+  program_list_t *pl;
+  program_list_t *next;
+
+  pl = pl_head;
+  while (pl != NULL)
+  {
+    next = pl->next;
+
+    if (pl->pid > 0)
+    {
+      kill (pl->pid, SIGTERM);
+      INFO ("exec plugin: Sent SIGTERM to %hu", (unsigned short int) pl->pid);
+    }
+
+    sfree (pl->user);
+    sfree (pl);
+
+    pl = next;
+  } /* while (pl) */
+  pl_head = NULL;
+
+  return (0);
+} /* int exec_shutdown */
+
 void module_register (modreg_e load)
 {
   if (load & MR_DATASETS)
@@ -368,6 +396,7 @@ void module_register (modreg_e load)
   {
     plugin_register_config ("exec", exec_config, config_keys, config_keys_num);
     plugin_register_read ("exec", exec_read);
+    plugin_register_shutdown ("exec", exec_shutdown);
   }
 } /* void module_register */
 
index aa5b67c..8524bea 100644 (file)
@@ -150,7 +150,8 @@ static int cache_insert (const data_set_t *ds, const value_list_t *vl)
        value_cache_t *vc;
        int i;
 
-       DEBUG ("ds->ds_num = %i; vl->values_len = %i;",
+       DEBUG ("unixsock plugin: cache_insert: ds->ds_num = %i;"
+                       " vl->values_len = %i;",
                        ds->ds_num, vl->values_len);
        assert (ds->ds_num == vl->values_len);