mirror of
https://gitlab.labs.nic.cz/labs/bird.git
synced 2024-05-11 16:54:54 +00:00
Rate limit for most abundant log messages
This commit is contained in:
@@ -30,6 +30,9 @@ static FILE *dbgf = NULL;
|
||||
static list *current_log_list;
|
||||
static list init_log_list;
|
||||
|
||||
bird_clock_t rate_limit_time = 5;
|
||||
int rate_limit_count = 5;
|
||||
|
||||
#ifdef HAVE_SYSLOG
|
||||
#include <sys/syslog.h>
|
||||
|
||||
@@ -126,6 +129,35 @@ log_msg(char *msg, ...)
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void
|
||||
log_rl(struct rate_limit *rl, char *msg, ...)
|
||||
{
|
||||
int class = 1;
|
||||
va_list args;
|
||||
|
||||
bird_clock_t delta = now - rl->timestamp;
|
||||
if ((0 <= delta) && (delta < rate_limit_time))
|
||||
{
|
||||
rl->count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
rl->timestamp = now;
|
||||
rl->count = 1;
|
||||
}
|
||||
|
||||
if (rl->count > rate_limit_count)
|
||||
return;
|
||||
|
||||
va_start(args, msg);
|
||||
if (*msg >= 1 && *msg <= 8)
|
||||
class = *msg++;
|
||||
vlog(class, msg, args);
|
||||
if (rl->count == rate_limit_count)
|
||||
vlog(class, "...", args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
/**
|
||||
* bug - report an internal error
|
||||
* @msg: a printf-like error message
|
||||
|
||||
Reference in New Issue
Block a user