/**
* collectd - src/rrdtool.c
- * Copyright (C) 2006 Florian octo Forster
+ * Copyright (C) 2006,2007 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
int values_num;
char **values;
time_t first_value;
+ time_t last_value;
};
typedef struct rrd_cache_s rrd_cache_t;
int status;
int i;
- memset (buffer, '\0', sizeof (buffer_len));
+ memset (buffer, '\0', buffer_len);
status = snprintf (buffer, buffer_len, "%u", (unsigned int) vl->time);
if ((status < 1) || (status >= buffer_len))
} /* int value_list_to_filename */
static rrd_cache_t *rrd_cache_insert (const char *filename,
- const char *value)
+ const char *value, time_t value_time)
{
rrd_cache_t *rc = NULL;
int new_rc = 0;
rc->values_num = 0;
rc->values = NULL;
rc->first_value = 0;
+ rc->last_value = 0;
new_rc = 1;
}
+ if (rc->last_value >= value_time)
+ {
+ WARNING ("rrdtool plugin: (rc->last_value = %u) >= (value_time = %u)",
+ (unsigned int) rc->last_value,
+ (unsigned int) value_time);
+ return (NULL);
+ }
+
rc->values = (char **) realloc ((void *) rc->values,
(rc->values_num + 1) * sizeof (char *));
if (rc->values == NULL)
rc->values_num++;
if (rc->values_num == 1)
- rc->first_value = time (NULL);
+ rc->first_value = value_time;
+ rc->last_value = value_time;
/* Insert if this is the first value */
if ((cache != NULL) && (new_rc == 1))
avl_insert (cache, cache_key, rc);
}
- DEBUG ("rrd_cache_insert (%s, %s) = %p", filename, value, (void *) rc);
+ DEBUG ("rrd_cache_insert (%s, %s, %u) = %p", filename, value,
+ (unsigned int) value_time, (void *) rc);
return (rc);
} /* rrd_cache_t *rrd_cache_insert */
}
pthread_mutex_lock (&cache_lock);
- rc = rrd_cache_insert (filename, values);
+ rc = rrd_cache_insert (filename, values, vl->time);
if (rc == NULL)
{
pthread_mutex_unlock (&cache_lock);
char *saveptr = NULL;
char *dummy;
char *ptr;
+ char *value_copy;
int *tmp_alloc;
- dummy = value;
+ value_copy = strdup (value);
+ if (value_copy == NULL)
+ return (1);
+
+ dummy = value_copy;
while ((ptr = strtok_r (dummy, ", \t", &saveptr)) != NULL)
{
dummy = NULL;
if (tmp_alloc == NULL)
{
fprintf (stderr, "rrdtool: realloc failed.\n");
+ free (value_copy);
return (1);
}
rra_timespans_custom = tmp_alloc;
if (rra_timespans_custom[rra_timespans_custom_num] != 0)
rra_timespans_custom_num++;
} /* while (strtok_r) */
-
+ free (value_copy);
}
else if (strcasecmp ("XFF", key) == 0)
{
return (0);
} /* int rrd_init */
-void module_register (modreg_e load)
+void module_register (void)
{
plugin_register_config ("rrdtool", rrd_config,
config_keys, config_keys_num);