#include "time.h"
#include "util.h"
+// When the daemon starts up, we should not collect everything straight away to
+// avoid any usage peaks. Therefore we will stagger all sources randomly across
+// N seconds.
+#define STAGGER 60
+
#define STEPSIZE 60 // seconds
// Interval after which the heartbeat function is being called again
}
static int collecty_source_register_heartbeat(collecty_source* self) {
+ uint64_t heartbeat = 0;
int r;
// No need to do this if we don't have a collect method
if (!self->impl->collect)
return 0;
+ // To avoid any load peaks, stagger sources
+ heartbeat = SEC_TO_USEC(rand() % STAGGER);
+
// Call the heartbeat function immediately
r = sd_event_add_time_relative(self->loop, &self->events.heartbeat,
- CLOCK_MONOTONIC, 0, 0, collecty_source_heartbeat, self);
+ CLOCK_MONOTONIC, heartbeat, 0, collecty_source_heartbeat, self);
if (r < 0) {
ERROR(self->ctx, "Failed to register the heartbeat timer: %s\n", strerror(-r));
return r;