rrdtool plugin: Fix flushing
authorPavel Rochnyack <pavel2000@ngs.ru>
Sun, 16 Jul 2017 15:56:05 +0000 (22:56 +0700)
committerFlorian Forster <octo@collectd.org>
Thu, 20 Jul 2017 05:52:08 +0000 (07:52 +0200)
* 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

src/collectd.conf.pod
src/rrdtool.c

index f88430a..27acc99 100644 (file)
@@ -6466,7 +6466,8 @@ one (exclusive).
 
 When the C<rrdtool> plugin uses a cache (by setting B<CacheTimeout>, see below)
 it writes all values for a certain RRD-file if the oldest value is older than
 
 When the C<rrdtool> plugin uses a cache (by setting B<CacheTimeout>, 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<CacheTimeout>.
+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<CacheFlush> is set, then the
 entire cache is searched for entries older than B<CacheTimeout> seconds and
 anymore for some reason (the computer was shut down, the network is broken,
 etc.) some values may still be in the cache. If B<CacheFlush> is set, then the
 entire cache is searched for entries older than B<CacheTimeout> 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.
 
 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<CacheTimeout>.
+If value of B<CacheFlush> less than value of B<CacheTimeout> then default value
+used too.
+
 =item B<CacheTimeout> I<Seconds>
 
 If this option is set to a value greater than zero, the C<rrdtool plugin> will
 =item B<CacheTimeout> I<Seconds>
 
 If this option is set to a value greater than zero, the C<rrdtool plugin> will
index d357cad..2a1a569 100644 (file)
@@ -505,7 +505,6 @@ static void rrd_cache_flush(cdtime_t timeout) {
         CDTIME_T_TO_DOUBLE(timeout));
 
   now = cdtime();
         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);
 
   /* 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))
 
   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);
 
 
   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);
     }
             "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;
   } 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;
   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;
     cache_flush_timeout = 10 * cache_timeout;
+  }
 
   pthread_mutex_unlock(&cache_lock);
 
 
   pthread_mutex_unlock(&cache_lock);