From: Michael Tremer Date: Sun, 28 Sep 2025 09:42:48 +0000 (+0000) Subject: module: Format the data sources X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e7898773246ad9211015fdbe8d4d15260696594a;p=telemetry.git module: Format the data sources Signed-off-by: Michael Tremer --- diff --git a/src/daemon/module.c b/src/daemon/module.c index 0af412a..2414e80 100644 --- a/src/daemon/module.c +++ b/src/daemon/module.c @@ -29,9 +29,11 @@ #include +#include "args.h" #include "ctx.h" #include "daemon.h" #include "module.h" +#include "util.h" // Interval after which the heartbeat function is being called again #define HEARTBEAT 60000000 // 60s @@ -270,11 +272,47 @@ int collecty_module_submit(collecty_module* self, } static int collecty_module_create_database(collecty_module* self, const char* path) { + collecty_args* args = NULL; + char min[24]; + char max[24]; + int r; + DEBUG(self->ctx, "Creating database for %s at %s\n", collecty_module_name(self), path); - // XXX TODO + // Allocate a new argument array + r = collecty_args_create(&args, self->ctx); + if (r < 0) + goto ERROR; - return 0; + // Add all data sources + for (const collecty_rrd_ds* ds = self->methods->rrd_dss; ds->field; ds++) { + // Format the minimum value + r = collecty_format_number(min, ds->min); + if (r < 0) + goto ERROR; + + // Format the maximum value + r = collecty_format_number(max, ds->max); + if (r < 0) + goto ERROR; + + // Add the DS line + r = collecty_args_push(args, "DS:%s:%s:%d:%s:%s", + ds->field, ds->type, HEARTBEAT * 2, min, max); + if (r < 0) + goto ERROR; + } + + // Dump all arguments + r = collecty_args_dump(args); + if (r < 0) + goto ERROR; + +ERROR: + if (args) + collecty_args_unref(args); + + return r; } /*