[collectd] [PATCH] make rrdcached.c accept RRD creation options

Thorsten von Eicken tve at rightscale.com
Fri Apr 30 17:08:04 CEST 2010


I patched rrdcached.c to accept the same RRD creation options as the 
rrdtool plugin accepts. It's not pretty in that it duplicates code, but 
it works. Patch for rrdcached.c and collectd.conf.pod below.
Cheers,
Thorsten


# diff -u src/rrdcached.c.orig src/rrdcached.c
--- src/rrdcached.c.orig        2010-04-30 01:23:45.000000000 +0000
+++ src/rrdcached.c     2010-04-30 14:59:00.000000000 +0000
@@ -25,6 +25,7 @@
  #include "utils_rrdcreate.h"

  #undef HAVE_CONFIG_H
+#include <rrd.h>
  #include <rrd_client.h>

  /*
@@ -36,6 +37,11 @@
    "DataDir",
    "CreateFiles",
    "CollectStatistics"
+  "StepSize",
+  "HeartBeat",
+  "RRARows",
+  "RRATimespan",
+  "XFF",
  };
  static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);

@@ -159,6 +165,19 @@
    return (0);
  } /* int value_list_to_filename */

+static int rrd_compare_numeric (const void *a_ptr, const void *b_ptr)
+{
+       int a = *((int *) a_ptr);
+       int b = *((int *) b_ptr);
+
+       if (a < b)
+               return (-1);
+       else if (a > b)
+               return (1);
+       else
+               return (0);
+} /* int rrd_compare_numeric */
+
  static int rc_config (const char *key, const char *value)
  {
    if (strcasecmp ("DataDir", key) == 0)
@@ -205,6 +224,83 @@
      else
        config_collect_stats = 1;
    }
+  else if (strcasecmp ("StepSize", key) == 0)
+  {
+    int temp = atoi (value);
+    if (temp > 0)
+      rrdcreate_config.stepsize = temp;
+  }
+  else if (strcasecmp ("HeartBeat", key) == 0)
+  {
+    int temp = atoi (value);
+    if (temp > 0)
+      rrdcreate_config.heartbeat = temp;
+  }
+  else if (strcasecmp ("RRARows", key) == 0)
+  {
+    int tmp = atoi (value);
+    if (tmp <= 0)
+    {
+      fprintf (stderr, "rrdtool: `RRARows' must "
+          "be greater than 0.\n");
+      ERROR ("rrdtool: `RRARows' must "
+          "be greater than 0.\n");
+      return (1);
+    }
+    rrdcreate_config.rrarows = tmp;
+  }
+  else if (strcasecmp ("RRATimespan", key) == 0)
+  {
+    char *saveptr = NULL;
+    char *dummy;
+    char *ptr;
+    char *value_copy;
+    int *tmp_alloc;
+
+    value_copy = strdup (value);
+    if (value_copy == NULL)
+      return (1);
+
+    dummy = value_copy;
+    while ((ptr = strtok_r (dummy, ", \t", &saveptr)) != NULL)
+    {
+      dummy = NULL;
+
+      tmp_alloc = realloc (rrdcreate_config.timespans,
+          sizeof (int) * (rrdcreate_config.timespans_num + 1));
+      if (tmp_alloc == NULL)
+      {
+        fprintf (stderr, "rrdtool: realloc failed.\n");
+        ERROR ("rrdtool: realloc failed.\n");
+        free (value_copy);
+        return (1);
+      }
+      rrdcreate_config.timespans = tmp_alloc;
+      rrdcreate_config.timespans[rrdcreate_config.timespans_num] = atoi 
(ptr);
+      if (rrdcreate_config.timespans[rrdcreate_config.timespans_num] != 0)
+        rrdcreate_config.timespans_num++;
+    } /* while (strtok_r) */
+
+    qsort (/* base = */ rrdcreate_config.timespans,
+        /* nmemb  = */ rrdcreate_config.timespans_num,
+        /* size   = */ sizeof (rrdcreate_config.timespans[0]),
+        /* compar = */ rrd_compare_numeric);
+
+    free (value_copy);
+  }
+  else if (strcasecmp ("XFF", key) == 0)
+  {
+    double tmp = atof (value);
+    if ((tmp < 0.0) || (tmp >= 1.0))
+    {
+      fprintf (stderr, "rrdtool: `XFF' must "
+          "be in the range 0 to 1 (exclusive).");
+      ERROR ("rrdtool: `XFF' must "
+          "be in the range 0 to 1 (exclusive).");
+      return (1);
+    }
+    rrdcreate_config.xff = tmp;
+  }
    else
    {
      return (-1);
@@ -230,11 +326,7 @@
    vl.values = values;
    vl.values_len = 1;

-  if ((strncmp ("unix:", daemon_address, strlen ("unix:")) == 0)
-      || (daemon_address[0] == '/'))
      sstrncpy (vl.host, hostname_g, sizeof (vl.host));
-  else
-    sstrncpy (vl.host, daemon_address, sizeof (vl.host));
    sstrncpy (vl.plugin, "rrdcached", sizeof (vl.plugin));

    head = NULL;

===============================================================================

# diff -u src/collectd.conf.pod.orig src/collectd.conf.pod
--- src/collectd.conf.pod.orig  2010-04-30 15:01:35.000000000 +0000
+++ src/collectd.conf.pod       2010-04-30 15:04:20.000000000 +0000
@@ -3413,6 +3413,8 @@
  setting should be set to an absolute path, so that a changed base 
directory
  does not result in RRD files being createdE<nbsp>/ expected in the 
wrong place.

+The C<rrdcached> plugin accepts the same B<StepSize>, B<HeartBeat>, 
B<RRARows>, B<RRATimespan>, and B<XFF> options as the C<rrdtool> plugin.
+
  =over 4

  =item B<DaemonAddress> I<Address>








More information about the collectd mailing list