[collectd] patch for rrdcached plugin
Thorsten von Eicken
tve at voneicken.com
Sat Oct 17 17:48:55 CEST 2009
Below is a patch so one can specify the RRD layout for the rrdcached
plugin the same way it's specified for the rrdtool plugin. The options
are the same, do you want a patch that duplicates the documentation?
Thorsten
diff -pur collectd-4.7.4/src/rrdcached.c collectd-4.7.4.MOD/src/rrdcached.c
--- collectd-4.7.4/src/rrdcached.c 2009-10-03 15:48:47.000000000 +0000
+++ collectd-4.7.4.MOD/src/rrdcached.c 2009-10-09 04:42:21.000000000 +0000
@@ -35,6 +35,11 @@ static const char *config_keys[] =
"DataDir",
"CreateFiles",
"CollectStatistics"
+ "StepSize",
+ "HeartBeat",
+ "RRARows",
+ "RRATimespan",
+ "XFF",
};
static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
@@ -147,6 +152,19 @@ static int value_list_to_filename (char
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)
@@ -197,6 +215,83 @@ static int rc_config (const char *key, c
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);
[
More information about the collectd
mailing list