Hello,
I work on a project consiting of daemon which runs periodically (10 - 300
seconds) some bits of code (check nginx status, check presence of some
processes, ...). This daemon runs on our servers. I use log4perl everywhere.
However sometimes an admin shuts down nginx for a while (0 - few hours) and do
some maintainance. Nginx code logs errors when HTTP requests fails. Log file
is then filled with same repeated message(s).
When I browsed through collectd (monitoring of everything) I found
utils_complain.[ch] which address this problem. It consists of structure which
is associated with one error message and functions for logging (complaining,
integrated into its logging system). It looks like this:
// inside collectd plugin, code executed periodically
c_complain(c, ERROR, "connecting failed");
The above logs only if (c->last + c->interval) is less or equal time(). c-
>interval is doubled on every call. c->last is last time of logging.
After success c->interval is set to 0 with:
c_release(c);
This module is a copy of this C code (a bit generalized). Altough it's really
simple piece of code, I thought it could be useful for other peoples and I
don't know any other use cases than logging so I'm posting it here (patch
attached). I'll make better docs ASAP.
Regards,
Thomas.
|