From: Michael Tremer Date: Sat, 27 Sep 2025 16:58:51 +0000 (+0000) Subject: queue: Store the timestamp with the sample X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6c982cc2a8a59ac85bb4c09047f095cb49d70c1c;p=collecty.git queue: Store the timestamp with the sample We can no longer store it this way because we are storing multiple samples in a single object now. Signed-off-by: Michael Tremer --- diff --git a/src/daemon/queue.c b/src/daemon/queue.c index 162d2ee..d032ec0 100644 --- a/src/daemon/queue.c +++ b/src/daemon/queue.c @@ -19,6 +19,7 @@ #############################################################################*/ #include +#include #include #include #include @@ -39,9 +40,6 @@ struct collecty_queue_object { // Object char* object; - // Timestamp - struct timeval t; - // Samples char** samples; unsigned int num_samples; @@ -216,17 +214,24 @@ static struct collecty_queue_object* collecty_queue_find_object( static int collecty_queue_object_append_sample(collecty_queue* self, collecty_module* module, const char* object, struct collecty_queue_object* o, const char* sample) { + struct timeval t = {}; char** samples = NULL; char* s = NULL; + int r; + + // Fetch the current timestamp + r = gettimeofday(&t, NULL); + if (r < 0) + return -errno; // Increase the size of the array samples = reallocarray(o->samples, o->num_samples + 1, sizeof(*o->samples)); if (!samples) return -errno; - // Copy the sample to the heap - s = strdup(sample); - if (!s) + // Prepend the timestamp to the sample + r = asprintf(&s, "%ld:%s", t.tv_sec, sample); + if (r < 0) return -errno; // Assign the sample @@ -263,13 +268,6 @@ int collecty_queue_submit(collecty_queue* self, // Reference the module o->module = collecty_module_ref(module); - // Fetch the current timestamp - r = gettimeofday(&o->t, NULL); - if (r < 0) { - r = -errno; - goto ERROR; - } - // Store the object if (o->object) { o->object = strdup(object);