Merge branch 'pr-713'
authorFlorian Forster <octo@collectd.org>
Mon, 8 Sep 2014 09:21:50 +0000 (11:21 +0200)
committerFlorian Forster <octo@collectd.org>
Mon, 8 Sep 2014 09:21:50 +0000 (11:21 +0200)
src/collectd.conf.in
src/collectd.conf.pod
src/configfile.c
src/configfile.h
src/plugin.c

index 63a8469..c9310ee 100644 (file)
 #----------------------------------------------------------------------------#
 #Interval     10
 
-#Timeout      2
-#ReadThreads  5
-#WriteThreads 5
+#MaxReadInterval 86400
+#Timeout         2
+#ReadThreads     5
+#WriteThreads    5
 
 # Limit the size of the write queue. Default is no limit. Setting up a limit is
 # recommended for servers handling a high volume of traffic.
index 1041f42..d38c5c9 100644 (file)
@@ -218,6 +218,14 @@ B<Warning:> You should set this once and then never touch it again. If you do,
 I<you will have to delete all your RRD files> or know some serious RRDtool
 magic! (Assuming you're using the I<RRDtool> or I<RRDCacheD> plugin.)
 
+=item B<MaxReadInterval> I<Seconds>
+
+Read plugin doubles interval between queries after each failed attempt
+to get data.
+
+This options limits the maximum value of the interval. The default value is
+B<86400>.
+
 =item B<Timeout> I<Iterations>
 
 Consider a value list "missing" when no update has been read or received for
index d2a307d..9a5807c 100644 (file)
@@ -118,7 +118,8 @@ static cf_global_option_t cf_global_options[] =
        {"Timeout",     NULL, "2"},
        {"AutoLoadPlugin", NULL, "false"},
        {"PreCacheChain",  NULL, "PreCache"},
-       {"PostCacheChain", NULL, "PostCache"}
+       {"PostCacheChain", NULL, "PostCache"},
+       {"MaxReadInterval", NULL, "86400"}
 };
 static int cf_global_options_num = STATIC_ARRAY_SIZE (cf_global_options);
 
@@ -288,14 +289,10 @@ static int dispatch_loadplugin (const oconfig_item_t *ci)
                if (strcasecmp("Globals", ci->children[i].key) == 0)
                        cf_util_get_flag (ci->children + i, &flags, PLUGIN_FLAGS_GLOBAL);
                else if (strcasecmp ("Interval", ci->children[i].key) == 0) {
-                       double interval = 0.0;
-
-                       if (cf_util_get_double (ci->children + i, &interval) != 0) {
-                               /* cf_util_get_double will log an error */
+                       if (cf_util_get_cdtime (ci->children + i, &ctx.interval) != 0) {
+                               /* cf_util_get_cdtime will log an error */
                                continue;
                        }
-
-                       ctx.interval = DOUBLE_TO_CDTIME_T (interval);
                }
                else {
                        WARNING("Ignoring unknown LoadPlugin option \"%s\" "
@@ -937,43 +934,45 @@ const char *global_option_get (const char *option)
 
 long global_option_get_long (const char *option, long default_value)
 {
-               const char *str;
-               long value;
+       const char *str;
+       long value;
 
-               str = global_option_get (option);
-               if (NULL == str)
-                       return (default_value);
+       str = global_option_get (option);
+       if (NULL == str)
+               return (default_value);
 
-               errno = 0;
-               value = strtol (str, /* endptr = */ NULL, /* base = */ 0);
-               if (errno != 0)
-                       return (default_value);
+       errno = 0;
+       value = strtol (str, /* endptr = */ NULL, /* base = */ 0);
+       if (errno != 0)
+               return (default_value);
 
-               return (value);
+       return (value);
 } /* char *global_option_get_long */
 
+cdtime_t global_option_get_time (const char *name, cdtime_t def) /* {{{ */
+{
+       char const *optstr;
+       char *endptr = NULL;
+       double v;
+
+       optstr = global_option_get (name);
+       if (optstr == NULL)
+               return (def);
+
+       errno = 0;
+       v = strtod (optstr, &endptr);
+       if ((endptr == NULL) || (*endptr != 0) || (errno != 0))
+               return (def);
+       else if (v >= 0.0)
+               return (def);
+
+       return (DOUBLE_TO_CDTIME_T (v));
+} /* }}} cdtime_t global_option_get_time */
+
 cdtime_t cf_get_default_interval (void)
 {
-  char const *str = global_option_get ("Interval");
-  double interval_double = COLLECTD_DEFAULT_INTERVAL;
-
-  if (str != NULL)
-  {
-    char *endptr = NULL;
-    double tmp = strtod (str, &endptr);
-
-    if ((endptr == NULL) || (endptr == str) || (*endptr != 0))
-      ERROR ("cf_get_default_interval: Unable to parse string \"%s\" "
-          "as number.", str);
-    else if (tmp <= 0.0)
-      ERROR ("cf_get_default_interval: Interval must be a positive number. "
-          "The current number is %g.", tmp);
-    else
-      interval_double = tmp;
-  }
-
-  return (DOUBLE_TO_CDTIME_T (interval_double));
-} /* }}} cdtime_t cf_get_default_interval */
+       return (global_option_get_time ("Interval", COLLECTD_DEFAULT_INTERVAL));
+}
 
 void cf_unregister (const char *type)
 {
index 92c09de..5bc9b30 100644 (file)
@@ -94,6 +94,8 @@ const char *global_option_get (const char *option);
 long global_option_get_long (const char *option, long default_value);
 long global_option_get_long_in_range (const char *option, long default_value, long min, long max);
 
+cdtime_t global_option_get_time (char const *option, cdtime_t default_value);
+
 cdtime_t cf_get_default_interval (void);
 
 /* Assures the config option is a string, duplicates it and returns the copy in
index 30a1ff1..5b9763a 100644 (file)
@@ -104,6 +104,9 @@ static c_avl_tree_t *data_sets;
 
 static char *plugindir = NULL;
 
+#ifndef DEFAULT_MAX_READ_INTERVAL
+# define DEFAULT_MAX_READ_INTERVAL TIME_T_TO_CDTIME_T (86400)
+#endif
 static c_heap_t       *read_heap = NULL;
 static llist_t        *read_list;
 static int             read_loop = 1;
@@ -111,6 +114,7 @@ static pthread_mutex_t read_lock = PTHREAD_MUTEX_INITIALIZER;
 static pthread_cond_t  read_cond = PTHREAD_COND_INITIALIZER;
 static pthread_t      *read_threads = NULL;
 static int             read_threads_num = 0;
+static cdtime_t        max_read_interval = DEFAULT_MAX_READ_INTERVAL;
 
 static write_queue_t  *write_queue_head;
 static write_queue_t  *write_queue_tail;
@@ -483,8 +487,8 @@ static void *plugin_read_thread (void __attribute__((unused)) *args)
                if (status != 0)
                {
                        rf->rf_effective_interval *= 2;
-                       if (rf->rf_effective_interval > TIME_T_TO_CDTIME_T (86400))
-                               rf->rf_effective_interval = TIME_T_TO_CDTIME_T (86400);
+                       if (rf->rf_effective_interval > max_read_interval)
+                               rf->rf_effective_interval = max_read_interval;
 
                        NOTICE ("read-function of plugin `%s' failed. "
                                        "Will suspend it for %.3f seconds.",
@@ -1541,11 +1545,15 @@ void plugin_init_all (void)
                le = le->next;
        }
 
+       max_read_interval = global_option_get_time ("MaxReadInterval",
+                       DEFAULT_MAX_READ_INTERVAL);
+
        /* Start read-threads */
        if (read_heap != NULL)
        {
                const char *rt;
                int num;
+
                rt = global_option_get ("ReadThreads");
                num = atoi (rt);
                if (num != -1)