From: Florian Forster Date: Mon, 10 Jul 2006 09:42:10 +0000 (+0200) Subject: Implemented `plugin_complain' and `plugin_relief' for better error-logging in plugins. X-Git-Tag: collectd-3.11.0~82 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=648535893fb2b67e189f71c17eb56d44d5661b49;p=collectd.git Implemented `plugin_complain' and `plugin_relief' for better error-logging in plugins. --- diff --git a/src/plugin.c b/src/plugin.c index 2f521570..be28671a 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -350,3 +350,54 @@ void plugin_submit (char *type, char *inst, char *val) else plugin_write (NULL, type, inst, val); } + +void plugin_complain (int level, complain_t *c, const char *format, ...) +{ + char message[512]; + va_list ap; + int step; + + if (c->delay > 0) + { + c->delay--; + return; + } + + step = atoi (COLLECTD_STEP); + assert (step > 0); + + if (c->interval < step) + c->interval = step; + else + c->interval *= 2; + + if (c->interval > 86400) + c->interval = 86400; + + c->delay = c->interval / step; + + va_start (ap, format); + vsnprintf (message, 512, format, ap); + message[511] = '\0'; + va_end (ap); + + syslog (level, message); +} + +void plugin_relief (int level, complain_t *c, const char *format, ...) +{ + char message[512]; + va_list ap; + + if (c->interval == 0) + return; + + c->interval = 0; + + va_start (ap, format); + vsnprintf (message, 512, format, ap); + message[511] = '\0'; + va_end (ap); + + syslog (level, message); +} diff --git a/src/plugin.h b/src/plugin.h index e1303c76..e1e2e7cf 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -1,3 +1,6 @@ +#ifndef PLUGIN_H +#define PLUGIN_H + /** * collectd - src/plugin.h * Copyright (C) 2005,2006 Florian octo Forster @@ -20,8 +23,14 @@ * Florian octo Forster **/ -#ifndef PLUGIN_H -#define PLUGIN_H +/* + * + */ +typedef struct complain_s +{ + unsigned int interval; /* how long we wait for reporting this error again */ + unsigned int delay; /* how many more iterations we still need to wait */ +} complain_t; /* * NAME @@ -117,4 +126,8 @@ void plugin_write (char *host, char *type, char *inst, char *val); void plugin_submit (char *type, char *inst, char *val); + +void plugin_complain (int level, complain_t *c, const char *format, ...); +void plugin_relief (int level, complain_t *c, const char *format, ...); + #endif /* PLUGIN_H */