]> git.ipfire.org Git - collecty.git/commitdiff
source: Complain if the heartbeat was called too late
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 4 Oct 2025 16:07:06 +0000 (16:07 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 4 Oct 2025 16:07:06 +0000 (16:07 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/source.c

index 479ed70ade8d513634f53e8d0d1049d57ee71add..6a2e9aee53f3d387ca0d48308841f8807250fabc 100644 (file)
@@ -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) {