DEBUG(self->ctx, "Heartbeat called for %s\n", collecty_module_name(self));
- // XXX TODO
+ // Call the collect method
+ r = self->methods->collect(self->ctx, self);
+ if (r < 0) {
+ ERROR(self->ctx, "collect() failed for %s: %s\n",
+ collecty_module_name(self), strerror(-r));
+ }
// Arm the timer again
r = sd_event_source_set_time(self->events.heartbeat, usec + HEARTBEAT);
static int collecty_module_register_heartbeat(collecty_module* self) {
int r;
+ // No need to do this if we don't have a collect method
+ if (!self->methods->collect)
+ return 0;
+
// Call the heartbeat function immediately
r = sd_event_add_time_relative(self->loop, &self->events.heartbeat,
CLOCK_MONOTONIC, 0, 0, collecty_module_heartbeat, self);
#include "ctx.h"
#include "daemon.h"
+typedef struct collecty_module collecty_module;
+
typedef struct collecty_module_methods {
const char* name;
// Free
int (*free)(collecty_ctx* ctx);
-} collecty_module_methods;
-typedef struct collecty_module collecty_module;
+ // Collect
+ int (*collect)(collecty_ctx* ctx, collecty_module* module);
+} collecty_module_methods;
int collecty_module_create(collecty_module** module,
collecty_ctx* ctx, collecty_daemon* daemon, const collecty_module_methods* methods);