From: Michael Tremer Date: Sat, 4 Oct 2025 16:07:06 +0000 (+0000) Subject: source: Complain if the heartbeat was called too late X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7ce7e1a2d5e6ca1a6560c7788a4575977bad6c53;p=collecty.git source: Complain if the heartbeat was called too late Signed-off-by: Michael Tremer --- diff --git a/src/daemon/source.c b/src/daemon/source.c index 479ed70..6a2e9ae 100644 --- a/src/daemon/source.c +++ b/src/daemon/source.c @@ -50,6 +50,9 @@ #define ERROR_THRESHOLD 5 #define FLAPPING_THRESHOLD 3 +// Complain if the heartbeat was delayed by more than this +#define DELAY_THRESHOLD 1000000 // 1 second + // Complain if collect() took longer than this time #define RUNTIME_THRESHOLD 250000 // 250 milliseconds @@ -255,6 +258,7 @@ static uint64_t collecty_source_elapsed_time(void) { static int collecty_source_heartbeat(sd_event_source* source, uint64_t usec, void* data) { collecty_source* self = data; uint64_t next_heartbeat; + uint64_t t_delay; uint64_t t_start; uint64_t t_end; int r; @@ -262,6 +266,15 @@ static int collecty_source_heartbeat(sd_event_source* source, uint64_t usec, voi // Store the start timestamp t_start = collecty_source_elapsed_time(); + // Compute how late we have been called + t_delay = t_start - usec; + + // Complain if we got called very late + if (t_delay >= DELAY_THRESHOLD) { + ERROR(self->ctx, "Heartbeat for %s was delayed by %.2lfms\n", + collecty_source_name(self), (double)t_delay / 1000); + } + // Call the collect method r = self->impl->collect(self->ctx, self); if (r < 0) {