Code

Timeout for missing values
authorAndrés J. Díaz <ajdiaz@connectical.com>
Thu, 17 Dec 2009 22:21:14 +0000 (23:21 +0100)
committerFlorian Forster <octo@huhu.verplant.org>
Sun, 25 Apr 2010 12:15:46 +0000 (14:15 +0200)
Hi!

I attach here a patch which adds Timeout option in configuration file.
This option is global (i.e. at the same level as Interval) and it's
the max number of intervals that a package can be missed before a
missing notification would be raised. By dafault collectd wait 2
intervals and it's a hardcoded value AFAIK, if plugin cannot get data
for more than 2 intervals, then (if it's an interesting value),
collectd send a missing notification. Setting Timeout to an high value
you can be more tolerant with that missing.

It's usefull on large networks. In my case, the company LAN is
distributed on distant locations and sometimes (due to network issues)
UDP packages are lost, I use the Timeout to be more tolerant to this
networks fails. For example setting Internval to 10 and Timeout to 6,
a  missing notification will be raised only if none data was reported
in last 60s.

I hope that things explained well enough, and (who knows!) maybe this
could be usefull to anybody ;)

Regards,
  Andrés

Signed-off-by: Florian Forster <octo@huhu.verplant.org>
src/collectd.c
src/collectd.h
src/configfile.c
src/utils_cache.c

index abab10f93c927eb013355da8d19659c5c69b0bca..9a4ba08ca7a3ea7ebbdedd1bfb6c265d1fe5e5a1 100644 (file)
@@ -41,6 +41,7 @@
  */
 char hostname_g[DATA_MAX_NAME_LEN];
 int  interval_g;
+int  timeout_g;
 #if HAVE_LIBKSTAT
 kstat_ctl_t *kc;
 #endif /* HAVE_LIBKSTAT */
@@ -148,6 +149,18 @@ static int init_global_variables (void)
        }
        DEBUG ("interval_g = %i;", interval_g);
 
+       str = global_option_get ("Timeout");
+       if (str == NULL)
+               str = "10";
+       timeout_g = atoi (str);
+       if (timeout_g <= 0)
+       {
+               fprintf (stderr, "Cannot set the timeout to a correct value.\n"
+                               "Please check your settings.\n");
+               return (-1);
+       }
+       DEBUG ("timeout_g = %i;", timeout_g);
+
        if (init_hostname () != 0)
                return (-1);
        DEBUG ("hostname_g = %s;", hostname_g);
index 957654bc0abcc446fd03c94fdc06b69de27878af..8849b30b221ffa776e6e0303acab8b9919e20b02 100644 (file)
@@ -300,5 +300,6 @@ typedef bool _Bool;
 
 extern char hostname_g[];
 extern int  interval_g;
+extern int  timeout_g;
 
 #endif /* COLLECTD_H */
index fe2bce3c365124fd700becaf29599b79f103b3d5..787ad0ea388485e247cdebb4027dec89f0218211 100644 (file)
@@ -99,6 +99,7 @@ static cf_global_option_t cf_global_options[] =
        {"FQDNLookup",  NULL, "false"},
        {"Interval",    NULL, "10"},
        {"ReadThreads", NULL, "5"},
+       {"Timeout",     NULL, "2"},
        {"PreCacheChain",  NULL, "PreCache"},
        {"PostCacheChain", NULL, "PostCache"}
 };
index 648c54de5b13b498df24b9ac3909eb2275544844..69ea864b99dbf1ddb2f35f8e82ae4078b0c8e9e6 100644 (file)
@@ -319,7 +319,7 @@ int uc_check_timeout (void)
   while (c_avl_iterator_next (iter, (void *) &key, (void *) &ce) == 0)
   {
     /* If entry has not been updated, add to `keys' array */
-    if ((now - ce->last_update) >= (2 * ce->interval))
+    if ((now - ce->last_update) >= (timeout_g * ce->interval))
     {
       char **tmp;