#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
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;
// 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) {