From: octo Date: Fri, 20 Jan 2006 09:46:10 +0000 (+0000) Subject: Changed the ping-module so it doesn't give up on socket-errors. X-Git-Tag: collectd-3.6.0~2 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=d3b918437ab91f7ad9c12f9157c6a19f973a64c4;p=collectd.git Changed the ping-module so it doesn't give up on socket-errors. --- diff --git a/ChangeLog b/ChangeLog index ea681cfe..838d16f6 100644 --- 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. diff --git a/src/collectd.c b/src/collectd.c index 38ff1567..c2c6dc0e 100644 --- a/src/collectd.c +++ b/src/collectd.c @@ -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 */ diff --git a/src/ping.c b/src/ping.c index bdb8de96..661aa65f 100644 --- a/src/ping.c +++ b/src/ping.c @@ -32,9 +32,11 @@ #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++) */ }