Merge branch 'collectd-5.5' into collectd-5.6
authorFlorian Forster <octo@collectd.org>
Fri, 7 Oct 2016 06:51:29 +0000 (08:51 +0200)
committerFlorian Forster <octo@collectd.org>
Fri, 7 Oct 2016 06:51:29 +0000 (08:51 +0200)
contrib/examples/myplugin.c
src/daemon/common.c
src/postgresql_default.conf
src/rrdcached.c
src/vserver.c

index e1b89f6..ab3ec2f 100644 (file)
@@ -104,7 +104,7 @@ static int my_read (void)
 
        /* it is strongly recommended to use a type defined in the types.db file
         * instead of a custom type */
-       sstrncpy (vl.type, "myplugin", sizeof (vl.plugin));
+       sstrncpy (vl.type, "myplugin", sizeof (vl.type));
        /* optionally set vl.plugin_instance and vl.type_instance to reasonable
         * values (default: "") */
 
@@ -114,7 +114,7 @@ static int my_read (void)
 
        /* A return value != 0 indicates an error and the plugin will be skipped
         * for an increasing amount of time. */
-    return 0;
+       return 0;
 } /* static int my_read (void) */
 
 /*
index 05b1199..7898ffb 100644 (file)
@@ -1124,7 +1124,7 @@ int parse_value (const char *value_orig, value_t *ret_value, int ds_type)
   }
 
   if (value == endptr) {
-    ERROR ("parse_value: Failed to parse string as %s: %s.",
+    ERROR ("parse_value: Failed to parse string as %s: \"%s\".",
         DS_TYPE_TO_STRING (ds_type), value);
     sfree (value);
     return -1;
index f905eb2..0aac41e 100644 (file)
 </Query>
 
 <Query query_plans>
-       Statement "SELECT sum(seq_scan) AS seq, \
-                       sum(seq_tup_read) AS seq_tup_read, \
-                       sum(idx_scan) AS idx, \
-                       sum(idx_tup_fetch) AS idx_tup_fetch \
+       Statement "SELECT coalesce(sum(seq_scan), 0) AS seq, \
+                         coalesce(sum(seq_tup_read), 0) AS seq_tup_read, \
+                         coalesce(sum(idx_scan), 0) AS idx, \
+                         coalesce(sum(idx_tup_fetch), 0) AS idx_tup_fetch \
                FROM pg_stat_user_tables;"
 
        <Result>
 
 <Query query_plans_by_table>
        Statement "SELECT schemaname, relname, \
-                       seq_scan AS seq, \
-                       seq_tup_read AS seq_tup_read, \
-                       idx_scan AS idx, \
-                       idx_tup_fetch AS idx_tup_fetch \
+                       coalesce(seq_scan, 0) AS seq, \
+                       coalesce(seq_tup_read, 0) AS seq_tup_read, \
+                       coalesce(idx_scan, 0) AS idx, \
+                       coalesce(idx_tup_fetch, 0) AS idx_tup_fetch \
                FROM pg_stat_user_tables;"
 
        <Result>
index 0425419..0b90405 100644 (file)
@@ -287,10 +287,31 @@ static int rc_config (oconfig_item_t *ci)
   return (0);
 } /* int rc_config */
 
+static int try_reconnect (void)
+{
+  int status;
+
+  rrdc_disconnect ();
+
+  rrd_clear_error ();
+  status = rrdc_connect (daemon_address);
+  if (status != 0)
+  {
+    ERROR ("rrdcached plugin: Failed to reconnect to RRDCacheD "
+        "at %s: %s (status=%d)", daemon_address, rrd_get_error (), status);
+    return (-1);
+  }
+
+  INFO ("rrdcached plugin: Successfully reconnected to RRDCacheD "
+      "at %s", daemon_address);
+  return (0);
+} /* int try_reconnect */
+
 static int rc_read (void)
 {
   int status;
   rrdc_stats_t *head;
+  _Bool retried = 0;
 
   value_t values[1];
   value_list_t vl = VALUE_LIST_INIT;
@@ -311,19 +332,35 @@ static int rc_read (void)
     sstrncpy (vl.host, daemon_address, sizeof (vl.host));
   sstrncpy (vl.plugin, "rrdcached", sizeof (vl.plugin));
 
+  rrd_clear_error ();
   status = rrdc_connect (daemon_address);
   if (status != 0)
   {
-    ERROR ("rrdcached plugin: rrdc_connect (%s) failed with status %i.",
-        daemon_address, status);
+    ERROR ("rrdcached plugin: Failed to connect to RRDCacheD "
+        "at %s: %s (status=%d)", daemon_address, rrd_get_error (), status);
     return (-1);
   }
 
-  head = NULL;
-  status = rrdc_stats_get (&head);
-  if (status != 0)
+  while (42)
   {
-    ERROR ("rrdcached plugin: rrdc_stats_get failed with status %i.", status);
+    /* The RRD client lib does not provide any means for checking a
+     * connection, hence we'll have to retry upon failed operations. */
+    head = NULL;
+    rrd_clear_error ();
+    status = rrdc_stats_get (&head);
+    if (status == 0)
+      break;
+
+    if (!retried)
+    {
+      retried = 1;
+      if (try_reconnect () == 0)
+        continue;
+      /* else: report the error and fail */
+    }
+
+    ERROR ("rrdcached plugin: rrdc_stats_get failed: %s (status=%i).",
+        rrd_get_error (), status);
     return (-1);
   }
 
@@ -411,6 +448,7 @@ static int rc_write (const data_set_t *ds, const value_list_t *vl,
   char values[512];
   char *values_array[2];
   int status;
+  _Bool retried = 0;
 
   if (daemon_address == NULL)
   {
@@ -467,20 +505,34 @@ static int rc_write (const data_set_t *ds, const value_list_t *vl,
     }
   }
 
+  rrd_clear_error ();
   status = rrdc_connect (daemon_address);
   if (status != 0)
   {
-    ERROR ("rrdcached plugin: rrdc_connect (%s) failed with status %i.",
-        daemon_address, status);
+    ERROR ("rrdcached plugin: Failed to connect to RRDCacheD "
+        "at %s: %s (status=%d)", daemon_address, rrd_get_error (), status);
     return (-1);
   }
 
-  status = rrdc_update (filename, /* values_num = */ 1, (void *) values_array);
-  if (status != 0)
+  while (42)
   {
-    ERROR ("rrdcached plugin: rrdc_update (%s, [%s], 1) failed with "
-        "status %i.",
-        filename, values_array[0], status);
+    /* The RRD client lib does not provide any means for checking a
+     * connection, hence we'll have to retry upon failed operations. */
+    rrd_clear_error ();
+    status = rrdc_update (filename, /* values_num = */ 1, (void *) values_array);
+    if (status == 0)
+      break;
+
+    if (!retried)
+    {
+      retried = 1;
+      if (try_reconnect () == 0)
+        continue;
+      /* else: report the error and fail */
+    }
+
+    ERROR ("rrdcached plugin: rrdc_update (%s, [%s], 1) failed: %s (status=%i)",
+        filename, values_array[0], rrd_get_error (), status);
     return (-1);
   }
 
@@ -493,6 +545,7 @@ static int rc_flush (__attribute__((unused)) cdtime_t timeout, /* {{{ */
 {
   char filename[PATH_MAX + 1];
   int status;
+  _Bool retried = 0;
 
   if (identifier == NULL)
     return (EINVAL);
@@ -502,19 +555,34 @@ static int rc_flush (__attribute__((unused)) cdtime_t timeout, /* {{{ */
   else
     ssnprintf (filename, sizeof (filename), "%s.rrd", identifier);
 
+  rrd_clear_error ();
   status = rrdc_connect (daemon_address);
   if (status != 0)
   {
-    ERROR ("rrdcached plugin: rrdc_connect (%s) failed with status %i.",
-        daemon_address, status);
+    ERROR ("rrdcached plugin: Failed to connect to RRDCacheD "
+        "at %s: %s (status=%d)", daemon_address, rrd_get_error (), status);
     return (-1);
   }
 
-  status = rrdc_flush (filename);
-  if (status != 0)
+  while (42)
   {
-    ERROR ("rrdcached plugin: rrdc_flush (%s) failed with status %i.",
-        filename, status);
+    /* The RRD client lib does not provide any means for checking a
+     * connection, hence we'll have to retry upon failed operations. */
+    rrd_clear_error ();
+    status = rrdc_flush (filename);
+    if (status == 0)
+      break;
+
+    if (!retried)
+    {
+      retried = 1;
+      if (try_reconnect () == 0)
+        continue;
+      /* else: report the error and fail */
+    }
+
+    ERROR ("rrdcached plugin: rrdc_flush (%s) failed: %s (status=%i).",
+        filename, rrd_get_error (), status);
     return (-1);
   }
   DEBUG ("rrdcached plugin: rrdc_flush (%s): Success.", filename);
index a730593..806fd92 100644 (file)
@@ -132,15 +132,7 @@ static derive_t vserver_get_sock_bytes(const char *s)
 
 static int vserver_read (void)
 {
-#if NAME_MAX < 1024
-# define DIRENT_BUFFER_SIZE (sizeof (struct dirent) + 1024 + 1)
-#else
-# define DIRENT_BUFFER_SIZE (sizeof (struct dirent) + NAME_MAX + 1)
-#endif
-
-       DIR                     *proc;
-       struct dirent   *dent; /* 42 */
-       char dirent_buffer[DIRENT_BUFFER_SIZE];
+       DIR *proc;
 
        errno = 0;
        proc = opendir (PROCDIR);
@@ -154,6 +146,7 @@ static int vserver_read (void)
 
        while (42)
        {
+               struct dirent *dent;
                int len;
                char file[BUFSIZE];
 
@@ -165,20 +158,20 @@ static int vserver_read (void)
 
                int status;
 
-               status = readdir_r (proc, (struct dirent *) dirent_buffer, &dent);
-               if (status != 0)
+               errno = 0;
+               dent = readdir (proc);
+               if (dent == NULL)
                {
                        char errbuf[4096];
-                       ERROR ("vserver plugin: readdir_r failed: %s",
-                                       sstrerror (errno, errbuf, sizeof (errbuf)));
+
+                       if (errno == 0) /* end of directory */
+                               break;
+
+                       ERROR ("vserver plugin: failed to read directory %s: %s",
+                                       PROCDIR, sstrerror (errno, errbuf, sizeof (errbuf)));
                        closedir (proc);
                        return (-1);
                }
-               else if (dent == NULL)
-               {
-                       /* end of directory */
-                       break;
-               }
 
                if (dent->d_name[0] == '.')
                        continue;