summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d1a32e2)
raw | patch | inline | side by side (parent: d1a32e2)
author | Florian Forster <octo@collectd.org> | |
Thu, 15 Nov 2012 12:55:04 +0000 (13:55 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Thu, 15 Nov 2012 12:55:04 +0000 (13:55 +0100) |
This should be able to replace "interval_g" in a global (i.e. non-plugin)
context, such as the interval in which timeouts are being checked.
The default value (10 seconds) is also configurable at compile time using
a define.
context, such as the interval in which timeouts are being checked.
The default value (10 seconds) is also configurable at compile time using
a define.
src/collectd.c | patch | blob | history | |
src/collectd.h | patch | blob | history | |
src/configfile.c | patch | blob | history | |
src/configfile.h | patch | blob | history | |
src/plugin.c | patch | blob | history |
diff --git a/src/collectd.c b/src/collectd.c
index c3dc7381baee532a6ef153050f6fba016337240c..cdb0ee89d1053ab09a4a8bda068410e31191c189 100644 (file)
--- a/src/collectd.c
+++ b/src/collectd.c
static int init_global_variables (void)
{
- const char *str;
-
- str = global_option_get ("Interval");
- if (str == NULL)
- {
- interval_g = TIME_T_TO_CDTIME_T (10);
- }
- else
- {
- double tmp;
-
- tmp = atof (str);
- if (tmp <= 0.0)
- {
- fprintf (stderr, "Cannot set the interval to a "
- "correct value.\n"
- "Please check your settings.\n");
- return (-1);
- }
+ char const *str;
- interval_g = DOUBLE_TO_CDTIME_T (tmp);
- }
+ interval_g = cf_get_default_interval ();
+ assert (interval_g > 0);
DEBUG ("interval_g = %.3f;", CDTIME_T_TO_DOUBLE (interval_g));
str = global_option_get ("Timeout");
static int do_loop (void)
{
+ cdtime_t interval = cf_get_default_interval ();
cdtime_t wait_until;
- wait_until = cdtime () + interval_g;
+ wait_until = cdtime () + interval;
while (loop == 0)
{
WARNING ("Not sleeping because the next interval is "
"%.3f seconds in the past!",
CDTIME_T_TO_DOUBLE (now - wait_until));
- wait_until = now + interval_g;
+ wait_until = now + interval;
continue;
}
CDTIME_T_TO_TIMESPEC (wait_until - now, &ts_wait);
- wait_until = wait_until + interval_g;
+ wait_until = wait_until + interval;
while ((loop == 0) && (nanosleep (&ts_wait, &ts_wait) != 0))
{
diff --git a/src/collectd.h b/src/collectd.h
index 4079ad1f2872c4d70aa708f0c523b3aed1f517fb..c0994d19276e501a1170ed2cfde979c112eece79 100644 (file)
--- a/src/collectd.h
+++ b/src/collectd.h
# define COLLECTD_GRP_NAME "collectd"
#endif
+#ifndef COLLECTD_DEFAULT_INTERVAL
+# define COLLECTD_DEFAULT_INTERVAL 10.0
+#endif
+
#define STATIC_ARRAY_LEN(array) (sizeof (array) / sizeof ((array)[0]))
/* Remove GNU specific __attribute__ settings when using another compiler */
diff --git a/src/configfile.c b/src/configfile.c
index b09bee8dbf66997ab96bea8ef33740d6d4ae362c..e22daf38c7630d00dfb27b66b129d8d4a60794ea 100644 (file)
--- a/src/configfile.c
+++ b/src/configfile.c
{"PIDFile", NULL, PIDFILE},
{"Hostname", NULL, NULL},
{"FQDNLookup", NULL, "true"},
- {"Interval", NULL, "10"},
+ {"Interval", NULL, NULL},
{"ReadThreads", NULL, "5"},
{"Timeout", NULL, "2"},
{"PreCacheChain", NULL, "PreCache"},
name = ci->values[0].value.string;
/* default to the global interval set before loading this plugin */
- ctx.interval = plugin_get_interval ();
+ memset (&ctx, 0, sizeof (ctx));
+ ctx.interval = cf_get_default_interval ();
/*
* XXX: Magic at work:
: cf_global_options[i].def);
} /* char *global_option_get */
+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 */
+
void cf_unregister (const char *type)
{
cf_callback_t *this, *prev;
diff --git a/src/configfile.h b/src/configfile.h
index 59ea55428e43e9752a91c3c9e82675fc0d7ba91b..b44a738c8beb00eb8fde547ae994a2277b0a7808 100644 (file)
--- a/src/configfile.h
+++ b/src/configfile.h
int global_option_set (const char *option, const char *value);
const char *global_option_get (const char *option);
+cdtime_t cf_get_default_interval (void);
+
/* Assures the config option is a string, duplicates it and returns the copy in
* "ret_string". If necessary "*ret_string" is freed first. Returns zero upon
* success. */
diff --git a/src/plugin.c b/src/plugin.c
index 22f89696d6d0bba6d51c168fdf0ebaebd836e9b7..f042b12543ad043e1e24a969ccdf125c9b8d0522 100644 (file)
--- a/src/plugin.c
+++ b/src/plugin.c
{
cdtime_t interval;
- const char *interval_str;
- double interval_dbl;
-
interval = plugin_get_ctx().interval;
if (interval > 0)
return interval;
- /* this should happen during initialization only */
- interval_str = global_option_get ("Interval");
- if (interval_str != NULL)
- {
- interval_dbl = atof (interval_str);
- if (interval_dbl > 0.0)
- interval = DOUBLE_TO_CDTIME_T (interval_dbl);
- }
-
- if (interval > 0)
- return interval;
- return TIME_T_TO_CDTIME_T (10);
+ return cf_get_default_interval ();
} /* cdtime_t plugin_get_interval */
typedef struct {