]> git.ipfire.org Git - telemetry.git/commitdiff
daemon: Initialize all graphs when the daemon starts
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 29 Sep 2025 17:53:01 +0000 (17:53 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 29 Sep 2025 17:53:01 +0000 (17:53 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/daemon/daemon.c

index c5adb6b84fcebac14e54b35fed78f5b25875f8f2..8a93aedcbb5d623282d6398ce3f0ab3136bcc028 100644 (file)
@@ -102,6 +102,8 @@ dist_collectyd_SOURCES = \
        src/daemon/graph.h \
        src/daemon/graph-bus.c \
        src/daemon/graph-bus.h \
+       src/daemon/graphs.c \
+       src/daemon/graphs.h \
        src/daemon/logging.c \
        src/daemon/logging.h \
        src/daemon/main.c \
index d45429e983a79567d5f31f8af39016603c7cde0f..92715b09842f28c8497d0dcf0fbaca01f6496503 100644 (file)
@@ -28,6 +28,7 @@
 #include "bus.h"
 #include "ctx.h"
 #include "daemon.h"
+#include "graphs.h"
 #include "graph-bus.h"
 #include "module.h"
 #include "modules.h"
@@ -54,15 +55,28 @@ struct collecty_daemon {
 
        // Queue
        collecty_queue* queue;
+
+       // Graphs
+       collecty_graphs* graphs;
 };
 
 static int collecty_daemon_init(sd_event_source* source, void* data) {
        collecty_daemon* self = data;
+       int r;
 
        DEBUG(self->ctx, "Initializing daemon...\n");
 
        // Initialize all modules
-       return collecty_modules_init(self->ctx, self);
+       r = collecty_modules_init(self->ctx, self);
+       if (r < 0)
+               return r;
+
+       // Initialize all graphs
+       r = collecty_graphs_create(&self->graphs, self->ctx, self);
+       if (r < 0)
+               return r;
+
+       return 0;
 }
 
 static int collecty_daemon_exit(sd_event_source* source, void* data) {
@@ -70,6 +84,12 @@ static int collecty_daemon_exit(sd_event_source* source, void* data) {
 
        DEBUG(self->ctx, "Cleaning up daemon...\n");
 
+       // Free all graphs
+       if (self->graphs) {
+               collecty_graphs_unref(self->graphs);
+               self->graphs = NULL;
+       }
+
        return 0;
 }
 
@@ -159,6 +179,8 @@ static void collecty_daemon_free(collecty_daemon* self) {
                sd_event_source_unref(self->events.init);
        if (self->events.exit)
                sd_event_source_unref(self->events.exit);
+       if (self->graphs)
+               collecty_graphs_unref(self->graphs);
        if (self->queue)
                collecty_queue_unref(self->queue);
        if (self->ctx)