author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Thu, 26 Oct 2006 20:32:19 +0000 (22:32 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Thu, 26 Oct 2006 20:32:19 +0000 (22:32 +0200) |
src/ping.c | patch | blob | history | |
src/swap.c | patch | blob | history |
diff --git a/src/ping.c b/src/ping.c
index 8e2c50b43b73880fff4bae121135bb4489e8681a..2a2f03eb39b80f062b652d4240c8fd3cddcee849 100644 (file)
--- a/src/ping.c
+++ b/src/ping.c
#include <netinet/in.h>
#include "liboping/oping.h"
+struct hostlist_s
+{
+ char *host;
+ int wait_time;
+ int wait_left;
+ struct hostlist_s *next;
+};
+typedef struct hostlist_s hostlist_t;
+
static pingobj_t *pingobj = NULL;
+static hostlist_t *hosts = NULL;
static char *file_template = "ping-%s.rrd";
};
static int config_keys_num = 2;
+static void add_hosts (void)
+{
+ hostlist_t *hl_this;
+ hostlist_t *hl_prev;
+
+ int step = atoi (COLLECTD_STEP);
+
+ hl_this = hosts;
+ hl_prev = NULL;
+ while (hl_this != NULL)
+ {
+ DBG ("host = %s, wait_left = %i, wait_time = %i, next = %p",
+ hl_this->host, hl_this->wait_left, hl_this->wait_time, (void *) hl_this->next);
+
+ if (hl_this->wait_left <= 0)
+ {
+ if (ping_host_add (pingobj, hl_this->host) == 0)
+ {
+ DBG ("Successfully added host %s", hl_this->host);
+ /* Remove the host from the linked list */
+ if (hl_prev != NULL)
+ hl_prev->next = hl_this->next;
+ else
+ hosts = hl_this->next;
+ free (hl_this->host);
+ free (hl_this);
+ hl_this = (hl_prev != NULL) ? hl_prev : hosts;
+ }
+ else
+ {
+ hl_this->wait_left = hl_this->wait_time;
+ hl_this->wait_time *= 2;
+ if (hl_this->wait_time > 86400)
+ hl_this->wait_time = 86400;
+ }
+ }
+ else
+ {
+ hl_this->wait_left -= step;
+ }
+
+ if (hl_this != NULL)
+ {
+ hl_prev = hl_this;
+ hl_this = hl_this->next;
+ }
+ }
+}
+
static void ping_init (void)
{
- return;
+ if (hosts != NULL)
+ add_hosts ();
}
static int ping_config (char *key, char *value)
if (strcasecmp (key, "host") == 0)
{
- if (ping_host_add (pingobj, value) < 0)
+ hostlist_t *hl;
+ char *host;
+ int step = atoi (COLLECTD_STEP);
+
+ if ((hl = (hostlist_t *) malloc (sizeof (hostlist_t))) == NULL)
{
- syslog (LOG_WARNING, "ping: `ping_host_add' failed: %s",
- ping_get_error (pingobj));
+ syslog (LOG_ERR, "ping plugin: malloc failed: %s",
+ strerror (errno));
+ return (1);
+ }
+ if ((host = strdup (value)) == NULL)
+ {
+ free (hl);
+ syslog (LOG_ERR, "ping plugin: strdup failed: %s",
+ strerror (errno));
return (1);
}
+
+ hl->host = host;
+ hl->wait_time = 2 * step;
+ hl->wait_left = 0;
+ hl->next = hosts;
+ hosts = hl;
}
else if (strcasecmp (key, "ttl") == 0)
{
if (pingobj == NULL)
return;
+ if (hosts != NULL)
+ add_hosts ();
+
if (ping_send (pingobj) < 0)
{
syslog (LOG_ERR, "ping: `ping_send' failed: %s",
diff --git a/src/swap.c b/src/swap.c
index f906c99dd1413e64819075a0edf2aff2e4a85b51..43275fc119540406960b2923ac58dee29c9bb1d2 100644 (file)
--- a/src/swap.c
+++ b/src/swap.c
size_t mib_len;
struct xsw_usage sw_usage;
size_t sw_usage_len;
- int status;
mib_len = 2;
mib[0] = CTL_VM;