rrdtool plugin: Raise interval of random_variation to match documentation
[collectd.git] / src / rrdtool.c
index d357cad..84fccef 100644 (file)
@@ -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);
@@ -606,9 +605,6 @@ static int rrd_cache_flush_identifier(cdtime_t timeout,
 } /* int rrd_cache_flush_identifier */
 
 static int64_t rrd_get_random_variation(void) {
-  long min;
-  long max;
-
   if (random_timeout == 0)
     return (0);
 
@@ -619,10 +615,7 @@ static int64_t rrd_get_random_variation(void) {
     random_timeout = cache_timeout;
   }
 
-  max = (long)(random_timeout / 2);
-  min = max - ((long)random_timeout);
-
-  return ((int64_t)cdrand_range(min, max));
+  return (int64_t)cdrand_range(-random_timeout, random_timeout);
 } /* int64_t rrd_get_random_variation */
 
 static int rrd_cache_insert(const char *filename, const char *value,
@@ -740,7 +733,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 +878,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 +1059,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);