X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrdtool.c;h=2c80762ecb905454f843620fd86cf3cd449ba8f7;hb=47b7950c0bd0ae0b3823b8bfc4442d6a5dad36c5;hp=b366a9c64166eeeae135f700b069e81578cac28a;hpb=0eff156c7816507fa1865b76e948574dd320fae0;p=collectd.git diff --git a/src/rrdtool.c b/src/rrdtool.c index b366a9c6..2c80762e 100644 --- a/src/rrdtool.c +++ b/src/rrdtool.c @@ -1,6 +1,6 @@ /** * collectd - src/rrdtool.c - * Copyright (C) 2006-2008 Florian octo Forster + * Copyright (C) 2006-2013 Florian octo Forster * Copyright (C) 2008-2008 Sebastian Harl * Copyright (C) 2009 Mariusz Gronczewski * @@ -18,7 +18,7 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * Authors: - * Florian octo Forster + * Florian octo Forster * Sebastian Harl * Mariusz Gronczewski **/ @@ -27,6 +27,7 @@ #include "plugin.h" #include "common.h" #include "utils_avltree.h" +#include "utils_random.h" #include "utils_rrdcreate.h" #include @@ -75,6 +76,7 @@ static const char *config_keys[] = { "CacheTimeout", "CacheFlush", + "CreateFilesAsync", "DataDir", "StepSize", "HeartBeat", @@ -102,7 +104,9 @@ static rrdcreate_config_t rrdcreate_config = /* timespans_num = */ 0, /* consolidation_functions = */ NULL, - /* consolidation_functions_num = */ 0 + /* consolidation_functions_num = */ 0, + + /* async = */ 0 }; /* XXX: If you need to lock both, cache_lock and queue_lock, at the same time, @@ -185,7 +189,7 @@ static int srrd_update (char *filename, char *template, if (status != 0) { WARNING ("rrdtool plugin: rrd_update_r failed: %s: %s", - argv[1], rrd_get_error ()); + filename, rrd_get_error ()); } sfree (new_argv); @@ -652,11 +656,8 @@ static int rrd_cache_flush_identifier (cdtime_t timeout, static int64_t rrd_get_random_variation (void) { - double dbl_timeout; - cdtime_t ctm_timeout; - double rand_fact; - _Bool negative; - int64_t ret; + long min; + long max; if (random_timeout <= 0) return (0); @@ -669,20 +670,10 @@ static int64_t rrd_get_random_variation (void) random_timeout = cache_timeout; } - /* This seems a bit complicated, but "random_timeout" is likely larger than - * RAND_MAX, so we can't simply use modulo here. */ - dbl_timeout = CDTIME_T_TO_DOUBLE (random_timeout); - rand_fact = ((double) random ()) - / ((double) RAND_MAX); - negative = (_Bool) (random () % 2); - - ctm_timeout = DOUBLE_TO_CDTIME_T (dbl_timeout * rand_fact); + max = (long) (random_timeout / 2); + min = max - ((long) random_timeout); - ret = (int64_t) ctm_timeout; - if (negative) - ret *= -1; - - return (ret); + return ((int64_t) cdrand_range (min, max)); } /* int64_t rrd_get_random_variation */ static int rrd_cache_insert (const char *filename, @@ -910,6 +901,8 @@ static int rrd_write (const data_set_t *ds, const value_list_t *vl, ds, vl, &rrdcreate_config); if (status != 0) return (-1); + else if (rrdcreate_config.async) + return (0); } else { @@ -998,7 +991,7 @@ static int rrd_config (const char *key, const char *value) } else if (strcasecmp ("StepSize", key) == 0) { - int temp = atoi (value); + unsigned long temp = strtoul (value, NULL, 0); if (temp > 0) rrdcreate_config.stepsize = temp; } @@ -1008,6 +1001,13 @@ static int rrd_config (const char *key, const char *value) if (temp > 0) rrdcreate_config.heartbeat = temp; } + else if (strcasecmp ("CreateFilesAsync", key) == 0) + { + if (IS_TRUE (value)) + rrdcreate_config.async = 1; + else + rrdcreate_config.async = 0; + } else if (strcasecmp ("RRARows", key) == 0) { int tmp = atoi (value); @@ -1161,22 +1161,9 @@ static int rrd_init (void) return (0); init_once = 1; - if (rrdcreate_config.stepsize < 0) - rrdcreate_config.stepsize = 0; if (rrdcreate_config.heartbeat <= 0) rrdcreate_config.heartbeat = 2 * rrdcreate_config.stepsize; - if ((rrdcreate_config.heartbeat > 0) - && (rrdcreate_config.heartbeat < CDTIME_T_TO_TIME_T (interval_g))) - WARNING ("rrdtool plugin: Your `heartbeat' is " - "smaller than your `interval'. This will " - "likely cause problems."); - else if ((rrdcreate_config.stepsize > 0) - && (rrdcreate_config.stepsize < CDTIME_T_TO_TIME_T (interval_g))) - WARNING ("rrdtool plugin: Your `stepsize' is " - "smaller than your `interval'. This will " - "create needlessly big RRD-files."); - /* Set the cache up */ pthread_mutex_lock (&cache_lock); @@ -1197,7 +1184,7 @@ static int rrd_init (void) pthread_mutex_unlock (&cache_lock); - status = pthread_create (&queue_thread, /* attr = */ NULL, + status = plugin_thread_create (&queue_thread, /* attr = */ NULL, rrd_queue_thread, /* args = */ NULL); if (status != 0) { @@ -1206,7 +1193,7 @@ static int rrd_init (void) } queue_thread_running = 1; - DEBUG ("rrdtool plugin: rrd_init: datadir = %s; stepsize = %i;" + DEBUG ("rrdtool plugin: rrd_init: datadir = %s; stepsize = %lu;" " heartbeat = %i; rrarows = %i; xff = %lf;", (datadir == NULL) ? "(null)" : datadir, rrdcreate_config.stepsize,