From: Pavel Rochnyack Date: Sun, 16 Jul 2017 15:56:05 +0000 (+0700) Subject: rrdtool plugin: Fix flushing X-Git-Tag: collectd-5.6.3~16 X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=c7cbb2af24de8b33186dd45b5731b87ea7152173 rrdtool plugin: Fix flushing * Value from wrong option was passed to rrd_cache_flush() * Variable cache_flush_timeout was used as cdtime_t type time while value was set as simple seconds * Added info message about CacheFlush ajusting * Documentation updated --- diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index f88430a0..27acc997 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -6466,7 +6466,8 @@ one (exclusive). When the C plugin uses a cache (by setting B, see below) it writes all values for a certain RRD-file if the oldest value is older than -(or equal to) the number of seconds specified. If some RRD-file is not updated +(or equal to) the number of seconds specified by B. +That check happens on new values arriwal. If some RRD-file is not updated anymore for some reason (the computer was shut down, the network is broken, etc.) some values may still be in the cache. If B is set, then the entire cache is searched for entries older than B seconds and @@ -6475,6 +6476,10 @@ does nothing under normal circumstances, this value should not be too small. 900 seconds might be a good value, though setting this to 7200 seconds doesn't normally do much harm either. +Default value for this option is 10x of B. +If value of B less than value of B then default value +used too. + =item B I If this option is set to a value greater than zero, the C will diff --git a/src/rrdtool.c b/src/rrdtool.c index d357cad0..2a1a5698 100644 --- a/src/rrdtool.c +++ b/src/rrdtool.c @@ -505,7 +505,6 @@ static void rrd_cache_flush(cdtime_t timeout) { CDTIME_T_TO_DOUBLE(timeout)); now = cdtime(); - timeout = TIME_T_TO_CDTIME_T(timeout); /* Build a list of entries to be flushed */ iter = c_avl_get_iterator(cache); @@ -740,7 +739,7 @@ static int rrd_cache_insert(const char *filename, const char *value, if ((cache_timeout > 0) && ((cdtime() - cache_flush_last) > cache_flush_timeout)) - rrd_cache_flush(cache_flush_timeout); + rrd_cache_flush(cache_timeout); pthread_mutex_unlock(&cache_lock); @@ -885,7 +884,7 @@ static int rrd_config(const char *key, const char *value) { "be greater than 0.\n"); return (1); } - cache_flush_timeout = tmp; + cache_flush_timeout = TIME_T_TO_CDTIME_T(tmp); } else if (strcasecmp("DataDir", key) == 0) { char *tmp; size_t len; @@ -1066,8 +1065,14 @@ static int rrd_init(void) { cache_flush_last = cdtime(); if (cache_timeout == 0) { cache_flush_timeout = 0; - } else if (cache_flush_timeout < cache_timeout) + } else if (cache_flush_timeout < cache_timeout) { + INFO("rrdtool plugin: \"CacheFlush %u\" is less than \"CacheTimeout %u\". " + "Ajusting \"CacheFlush\" to %u seconds.", + (unsigned int)CDTIME_T_TO_TIME_T(cache_flush_timeout), + (unsigned int)CDTIME_T_TO_TIME_T(cache_timeout), + (unsigned int)CDTIME_T_TO_TIME_T(cache_timeout * 10)); cache_flush_timeout = 10 * cache_timeout; + } pthread_mutex_unlock(&cache_lock);