Code

Changed the ping-module so it doesn't give up on socket-errors.
authorocto <octo>
Fri, 20 Jan 2006 09:46:10 +0000 (09:46 +0000)
committerocto <octo>
Fri, 20 Jan 2006 09:46:10 +0000 (09:46 +0000)
ChangeLog
src/collectd.c
src/ping.c

index ea681cfedebb9e2c257dbea90226033d71672fe3..838d16f6ca71abb450a7aad479bf4e414ef98d03 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,9 @@
          plugins.
        * A `df' plugin has been added.
        * A `mysql' plugin has been added.
+       * The `plugin' module doesn't entirely give up hope when a socket
+         error occured, but will back of and increase the intervals between
+         tries.
 
 2005-12-18, Version 3.5.1
        * The PID-file is now deleted correctly when shutting down the daemon.
index 38ff1567e146d8996738efb20b4eea1720a4419a..c2c6dc0eb64d16d0a8ac3c422a453eaf7b1440e6 100644 (file)
@@ -37,11 +37,6 @@ static int loop = 0;
 kstat_ctl_t *kc;
 #endif /* HAVE_LIBKSTAT */
 
-#if COLLECT_PING
-char *pinghosts[MAX_PINGHOSTS];
-int   num_pinghosts = 0;
-#endif
-
 /*
  * exported variables
  */
index bdb8de9652b3a1f8551ba5850cb987b029a7f160..661aa65f07fd39d20104c9d1bc00e6697b12b2cc 100644 (file)
 
 #define MAX_PINGHOSTS 32
 
-extern char *pinghosts[MAX_PINGHOSTS];
-extern int   num_pinghosts;
-static int   pingerrors[MAX_PINGHOSTS];
+static char *hosts[MAX_PINGHOSTS];
+static int   hosts_flags[MAX_PINGHOSTS];
+static int   hosts_disable[MAX_PINGHOSTS];
+static int   hosts_backoff[MAX_PINGHOSTS];
+static int   num_pinghosts;
 
 static char *file_template = "ping-%s.rrd";
 
@@ -56,8 +58,12 @@ static void ping_init (void)
 {
        int i;
 
-       for (i = 0; i < num_pinghosts; i++)
-               pingerrors[i] = 0;
+       for (i = 0; i < MAX_PINGHOSTS; i++)
+       {
+               hosts_flags[i] = 0;
+               hosts_disable[i] = 0;
+               hosts_backoff[i] = 1;
+       }
 
        return;
 }
@@ -72,13 +78,13 @@ static int ping_config (char *key, char *value)
        {
                return (1);
        }
-       else if ((pinghosts[num_pinghosts] = strdup (value)) == NULL)
+       else if ((hosts[num_pinghosts] = strdup (value)) == NULL)
        {
                return (2);
        }
        else
        {
-               pingerrors[num_pinghosts] = 0;
+               hosts_flags[num_pinghosts] = 0;
                num_pinghosts++;
                return (0);
        }
@@ -117,41 +123,49 @@ static void ping_read (void)
 
        for (i = 0; i < num_pinghosts; i++)
        {
-               if (pingerrors[i] & 0x30)
+               if (hosts_disable[i] > 0)
+               {
+                       hosts_disable[i]--;
                        continue;
+               }
                
-               ping = tpinghost (pinghosts[i]);
+               ping = tpinghost (hosts[i]);
 
                switch (ping)
                {
                        case 0:
-                               if (!(pingerrors[i] & 0x01))
-                                       syslog (LOG_WARNING, "ping %s: Connection timed out.", pinghosts[i]);
-                               pingerrors[i] |= 0x01;
+                               if (!(hosts_flags[i] & 0x01))
+                                       syslog (LOG_WARNING, "ping %s: Connection timed out.", hosts[i]);
+                               hosts_flags[i] |= 0x01;
                                break;
 
                        case -1:
-                               if (!(pingerrors[i] & 0x02))
-                                       syslog (LOG_WARNING, "ping %s: Host or service is not reachable.", pinghosts[i]);
-                               pingerrors[i] |= 0x02;
+                               if (!(hosts_flags[i] & 0x02))
+                                       syslog (LOG_WARNING, "ping %s: Host or service is not reachable.", hosts[i]);
+                               hosts_flags[i] |= 0x02;
                                break;
 
                        case -2:
-                               syslog (LOG_ERR, "ping %s: Socket error. Ping will be disabled.", pinghosts[i]);
-                               pingerrors[i] |= 0x10;
+                               syslog (LOG_ERR, "ping %s: Socket error. Ping will be disabled for %i iteration(s).",
+                                               hosts[i], hosts_backoff[i]);
+                               hosts_disable[i] = hosts_backoff[i];
+                               if (hosts_backoff[i] < 8192) /* 22 3/4 hours */
+                                       hosts_backoff[i] *= 2;
+                               hosts_flags[i] |= 0x10;
                                break;
 
                        case -3:
-                               if (!(pingerrors[i] & 0x04))
-                                       syslog (LOG_WARNING, "ping %s: Connection refused.", pinghosts[i]);
-                               pingerrors[i] |= 0x04;
+                               if (!(hosts_flags[i] & 0x04))
+                                       syslog (LOG_WARNING, "ping %s: Connection refused.", hosts[i]);
+                               hosts_flags[i] |= 0x04;
                                break;
 
                        default:
-                               if (pingerrors[i] != 0x00)
-                                       syslog (LOG_NOTICE, "ping %s: Back to normal: %ims.", pinghosts[i], ping);
-                               pingerrors[i] = 0x00;
-                               ping_submit (ping, pinghosts[i]);
+                               if (hosts_flags[i] != 0x00)
+                                       syslog (LOG_NOTICE, "ping %s: Back to normal: %ims.", hosts[i], ping);
+                               hosts_flags[i] = 0x00;
+                               hosts_backoff[i] = 1;
+                               ping_submit (ping, hosts[i]);
                } /* switch (ping) */
        } /* for (i = 0; i < num_pinghosts; i++) */
 }