Merge branch 'collectd-4.9' into collectd-4.10
authorFlorian Forster <octo@leeloo.lan.home.verplant.org>
Tue, 17 Aug 2010 16:53:29 +0000 (18:53 +0200)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Tue, 17 Aug 2010 16:53:29 +0000 (18:53 +0200)
src/collectd-perl.pod
src/collectd.conf.pod
src/configfile.c
src/curl_json.c
src/plugin.c
src/utils_match.c
src/utils_match.h

index 5637053..5c11b65 100644 (file)
@@ -4,7 +4,9 @@ collectd-perl - Documentation of collectd's C<perl plugin>
 
 =head1 SYNOPSIS
 
-  LoadPlugin perl
+  <LoadPlugin perl>
+    Globals true
+  </LoadPlugin>
   # ...
   <Plugin perl>
     IncludeDir "/path/to/perl/plugins"
@@ -25,6 +27,12 @@ for collectd in Perl. This is a lot more efficient than executing a
 Perl-script every time you want to read a value with the C<exec plugin> (see
 L<collectd-exec(5)>) and provides a lot more functionality, too.
 
+When loading the C<perl plugin>, the B<Globals> option should be enabled.
+Else, the perl plugin will fail to load any Perl modules implemented in C,
+which includes, amongst many others, the B<threads> module used by the plugin
+itself. See the documentation of the B<Globals> option in L<collectd.conf(5)>
+for details.
+
 =head1 CONFIGURATION
 
 =over 4
index cc448a0..4faba99 100644 (file)
@@ -57,6 +57,33 @@ directory for the daemon.
 Loads the plugin I<Plugin>. There must be at least one such line or B<collectd>
 will be mostly useless.
 
+Starting with collectd 4.9, this may also be a block in which further options
+affecting the behavior of B<LoadPlugin> may be specified. The following
+options are allowed inside a B<LoadPlugin> block:
+
+  <LoadPlugin perl>
+    Globals true
+  </LoadPlugin>
+
+=over 4
+
+=item B<Globals> B<true|false>
+
+If enabled, collectd will export all global symbols of the plugin (and of all
+libraries loaded as dependencies of the plugin) and, thus, makes those symbols
+available for resolving unresolved symbols in subsequently loaded plugins if
+that is supported by your system. By default, this is disabled.
+
+This is useful (or possibly even required), e.E<nbsp>g., when loading a plugin
+that embeds some scripting language into the daemon (e.E<nbsp>g. the C<perl>
+or C<python> plugins). Scripting languages usually provide means to load
+extensions written in C. Those extensions require symbols provided by the
+interpreter, which is loaded as a dependency of the respective collectd
+plugin. See the documentation of those plugins (e.E<nbsp>g.,
+L<collectd-perl(5)> or L<collectd-python(5)>) for details.
+
+=back
+
 =item B<Include> I<Path>
 
 If I<Path> points to a file, includes that file. If I<Path> points to a
@@ -4175,25 +4202,37 @@ Use the last number found.
 
 =item B<CounterSet>
 
-The matched number is a counter. Simply sets the internal counter to this
-value.
+=item B<DeriveSet>
+
+=item B<AbsoluteSet>
+
+The matched number is a counter. Simply I<sets> the internal counter to this
+value. Variants exist for C<COUNTER>, C<DERIVE>, and C<ABSOLUTE> data sources.
 
 =item B<CounterAdd>
 
-Add the matched value to the internal counter.
+=item B<DeriveAdd>
+
+Add the matched value to the internal counter. In case of B<DeriveAdd>, the
+matched number may be negative, which will effectively subtract from the
+internal counter.
 
 =item B<CounterInc>
 
-Increase the internal counter by one. This B<DSType> is the only one that does
-not use the matched subexpression, but simply counts the number of matched
+=item B<DeriveInc>
+
+Increase the internal counter by one. These B<DSType> are the only ones that do
+not use the matched subexpression, but simply count the number of matched
 lines. Thus, you may use a regular expression without submatch in this case.
 
 =back
 
 As you'd expect the B<Gauge*> types interpret the submatch as a floating point
-number, using L<strtod(3)>. The B<CounterSet> and B<CounterAdd> interpret the
-submatch as an integer using L<strtoll(3)>. B<CounterInc> does not use the
-submatch at all and it may be omitted in this case.
+number, using L<strtod(3)>. The B<Counter*> and B<AbsoluteSet> types interpret
+the submatch as an unsigned integer using L<strtoull(3)>. The B<Derive*> types
+interpret the submatch as a signed integer using L<strtoll(3)>. B<CounterInc>
+and B<DeriveInc> do not use the submatch at all and it may be omitted in this
+case.
 
 =item B<Type> I<Type>
 
index 787ad0e..0b7786f 100644 (file)
@@ -701,11 +701,10 @@ static oconfig_item_t *cf_read_generic (const char *path, int depth)
                if (status != 0)
                {
                        char errbuf[1024];
-                       ERROR ("configfile: stat (%s) failed: %s",
+                       WARNING ("configfile: stat (%s) failed: %s",
                                        path_ptr,
                                        sstrerror (errno, errbuf, sizeof (errbuf)));
-                       oconfig_free (root);
-                       return (NULL);
+                       continue;
                }
 
                if (S_ISREG (statbuf.st_mode))
@@ -714,7 +713,7 @@ static oconfig_item_t *cf_read_generic (const char *path, int depth)
                        temp = cf_read_dir (path_ptr, depth);
                else
                {
-                       ERROR ("configfile: %s is neither a file nor a "
+                       WARNING ("configfile: %s is neither a file nor a "
                                        "directory.", path);
                        continue;
                }
@@ -731,6 +730,12 @@ static oconfig_item_t *cf_read_generic (const char *path, int depth)
 
        wordfree (&we);
 
+       if (root->children == NULL)
+       {
+               oconfig_free (root);
+               return (NULL);
+       }
+
        return (root);
 } /* oconfig_item_t *cf_read_generic */
 /* #endif HAVE_WORDEXP_H */
index 03ef6a3..21deed6 100644 (file)
@@ -1,7 +1,7 @@
 /**
  * collectd - src/curl_json.c
  * Copyright (C) 2009       Doug MacEachern
- * Copyright (C) 2006-2009  Florian octo Forster
+ * Copyright (C) 2006-2010  Florian octo Forster
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
@@ -130,59 +130,57 @@ static int cj_get_type (cj_key_t *key)
 }
 
 /* yajl callbacks */
-static int cj_cb_integer (void *ctx, long val)
+#define CJ_CB_ABORT    0
+#define CJ_CB_CONTINUE 1
+
+/* "number" may not be null terminated, so copy it into a buffer before
+ * parsing. */
+static int cj_cb_number (void *ctx,
+    const char *number, unsigned int number_len)
 {
+  char buffer[number_len + 1];
+
   cj_t *db = (cj_t *)ctx;
   cj_key_t *key = db->state[db->depth].key;
+  char *endptr;
+  value_t vt;
+  int type;
 
-  if (key != NULL)
-  {
-    value_t vt;
-    int type;
+  if (key == NULL)
+    return (CJ_CB_CONTINUE);
 
-    type = cj_get_type (key);
-    if (type == DS_TYPE_COUNTER)
-      vt.counter = (counter_t) val;
-    else if (type == DS_TYPE_GAUGE)
-      vt.gauge = (gauge_t) val;
-    else if (type == DS_TYPE_DERIVE)
-      vt.derive = (derive_t) val;
-    else if (type == DS_TYPE_ABSOLUTE)
-      vt.absolute = (absolute_t) val;
-    else
-      return 0;
+  memcpy (buffer, number, number_len);
+  buffer[sizeof (buffer) - 1] = 0;
 
-    cj_submit (db, key, &vt);
-  }
-  return 1;
-}
+  type = cj_get_type (key);
 
-static int cj_cb_double (void *ctx, double val)
-{
-  cj_t *db = (cj_t *)ctx;
-  cj_key_t *key = db->state[db->depth].key;
+  endptr = NULL;
+  errno = 0;
 
-  if (key != NULL)
+  if (type == DS_TYPE_COUNTER)
+    vt.counter = (counter_t) strtoull (buffer, &endptr, /* base = */ 0);
+  else if (type == DS_TYPE_GAUGE)
+    vt.gauge = (gauge_t) strtod (buffer, &endptr);
+  else if (type == DS_TYPE_DERIVE)
+    vt.derive = (derive_t) strtoll (buffer, &endptr, /* base = */ 0);
+  else if (type == DS_TYPE_ABSOLUTE)
+    vt.absolute = (absolute_t) strtoull (buffer, &endptr, /* base = */ 0);
+  else
   {
-    value_t vt;
-    int type;
-
-    type = cj_get_type (key);
-    if (type == DS_TYPE_COUNTER)
-      vt.counter = (counter_t) val;
-    else if (type == DS_TYPE_GAUGE)
-      vt.gauge = (gauge_t) val;
-    else if (type == DS_TYPE_DERIVE)
-      vt.derive = (derive_t) val;
-    else if (type == DS_TYPE_ABSOLUTE)
-      vt.absolute = (absolute_t) val;
-    else
-      return 0;
+    ERROR ("curl_json plugin: Unknown data source type: \"%s\"", key->type);
+    return (CJ_CB_ABORT);
+  }
 
-    cj_submit (db, key, &vt);
+  if ((endptr == &buffer[0]) || (errno != 0))
+  {
+    NOTICE ("curl_json plugin: Overflow while parsing number. "
+        "Ignoring this value.");
+    return (CJ_CB_CONTINUE);
   }
-  return 1;
-}
+
+  cj_submit (db, key, &vt);
+  return (CJ_CB_CONTINUE);
+} /* int cj_cb_number */
 
 static int cj_cb_map_key (void *ctx, const unsigned char *val,
                             unsigned int len)
@@ -209,7 +207,7 @@ static int cj_cb_map_key (void *ctx, const unsigned char *val,
       db->state[db->depth].key = NULL;
   }
 
-  return 1;
+  return (CJ_CB_CONTINUE);
 }
 
 static int cj_cb_string (void *ctx, const unsigned char *val,
@@ -220,7 +218,7 @@ static int cj_cb_string (void *ctx, const unsigned char *val,
   char *ptr;
 
   if (db->depth != 1) /* e.g. _all_dbs */
-    return 1;
+    return (CJ_CB_CONTINUE);
 
   cj_cb_map_key (ctx, val, len); /* same logic */
 
@@ -242,7 +240,7 @@ static int cj_cb_string (void *ctx, const unsigned char *val,
     cj_curl_perform (db, curl);
     curl_easy_cleanup (curl);
   }
-  return 1;
+  return (CJ_CB_CONTINUE);
 }
 
 static int cj_cb_start (void *ctx)
@@ -251,9 +249,9 @@ static int cj_cb_start (void *ctx)
   if (++db->depth >= YAJL_MAX_DEPTH)
   {
     ERROR ("curl_json plugin: %s depth exceeds max, aborting.", db->url);
-    return 0;
+    return (CJ_CB_ABORT);
   }
-  return 1;
+  return (CJ_CB_CONTINUE);
 }
 
 static int cj_cb_end (void *ctx)
@@ -261,7 +259,7 @@ static int cj_cb_end (void *ctx)
   cj_t *db = (cj_t *)ctx;
   db->state[db->depth].tree = NULL;
   --db->depth;
-  return 1;
+  return (CJ_CB_CONTINUE);
 }
 
 static int cj_cb_start_map (void *ctx)
@@ -287,9 +285,9 @@ static int cj_cb_end_array (void * ctx)
 static yajl_callbacks ycallbacks = {
   NULL, /* null */
   NULL, /* boolean */
-  cj_cb_integer,
-  cj_cb_double,
-  NULL, /* number */
+  NULL, /* integer */
+  NULL, /* double */
+  cj_cb_number,
   cj_cb_string,
   cj_cb_start_map,
   cj_cb_map_key,
@@ -777,7 +775,8 @@ static int cj_curl_perform (cj_t *db, CURL *curl) /* {{{ */
   curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url);
   curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &rc);
 
-  if (rc != 200)
+  /* The response code is zero if a non-HTTP transport was used. */
+  if ((rc != 0) && (rc != 200))
   {
     ERROR ("curl_json plugin: curl_easy_perform failed with response code %ld (%s)",
            rc, url);
index 4a3c917..af894d5 100644 (file)
@@ -1374,7 +1374,12 @@ int plugin_dispatch_values (value_list_t *vl)
 
        if (c_avl_get (data_sets, vl->type, (void *) &ds) != 0)
        {
-               INFO ("plugin_dispatch_values: Dataset not found: %s", vl->type);
+               char ident[6 * DATA_MAX_NAME_LEN];
+
+               FORMAT_VL (ident, sizeof (ident), vl);
+               INFO ("plugin_dispatch_values: Dataset not found: %s "
+                               "(from \"%s\"), check your types.db!",
+                               vl->type, ident);
                return (-1);
        }
 
index 0f87bc0..4d4b57d 100644 (file)
@@ -83,7 +83,7 @@ static int default_callback (const char __attribute__((unused)) *str,
     if (matches_num < 2)
       return (-1);
 
-    value = strtod (matches[1], &endptr);
+    value = (gauge_t) strtod (matches[1], &endptr);
     if (matches[1] == endptr)
       return (-1);
 
@@ -131,7 +131,7 @@ static int default_callback (const char __attribute__((unused)) *str,
     if (matches_num < 2)
       return (-1);
 
-    value = strtoll (matches[1], &endptr, 0);
+    value = (counter_t) strtoull (matches[1], &endptr, 0);
     if (matches[1] == endptr)
       return (-1);
 
@@ -162,7 +162,7 @@ static int default_callback (const char __attribute__((unused)) *str,
     if (matches_num < 2)
       return (-1);
 
-    value = strtoll (matches[1], &endptr, 0);
+    value = (derive_t) strtoll (matches[1], &endptr, 0);
     if (matches[1] == endptr)
       return (-1);
 
@@ -186,7 +186,7 @@ static int default_callback (const char __attribute__((unused)) *str,
     if (matches_num < 2)
       return (-1);
 
-    value = strtoll (matches[1], &endptr, 0);
+    value = (absolute_t) strtoull (matches[1], &endptr, 0);
     if (matches[1] == endptr)
       return (-1);
 
index 9e47d5c..36abe30 100644 (file)
 /*
  * Defines
  */
-#define UTILS_MATCH_DS_TYPE_GAUGE   0x10
-#define UTILS_MATCH_DS_TYPE_COUNTER 0x20
-#define UTILS_MATCH_DS_TYPE_DERIVE 0x30
-#define UTILS_MATCH_DS_TYPE_ABSOLUTE 0x40
+#define UTILS_MATCH_DS_TYPE_GAUGE    0x10
+#define UTILS_MATCH_DS_TYPE_COUNTER  0x20
+#define UTILS_MATCH_DS_TYPE_DERIVE   0x40
+#define UTILS_MATCH_DS_TYPE_ABSOLUTE 0x80
 
 #define UTILS_MATCH_CF_GAUGE_AVERAGE 0x01
 #define UTILS_MATCH_CF_GAUGE_MIN     0x02