]> git.ipfire.org Git - collecty.git/commitdiff
daemon: Rename modules to sources
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 3 Oct 2025 11:31:44 +0000 (11:31 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 3 Oct 2025 11:31:44 +0000 (11:31 +0000)
This makes more sense as the graphs have now been split into their own
modules, and so we won't have a too generic term for the sources.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
18 files changed:
Makefile.am
src/daemon/daemon.c
src/daemon/daemon.h
src/daemon/graph.c
src/daemon/graph.h
src/daemon/graphs/loadavg.c
src/daemon/queue.c
src/daemon/queue.h
src/daemon/source.c [moved from src/daemon/module.c with 81% similarity]
src/daemon/source.h [moved from src/daemon/module.h with 75% similarity]
src/daemon/sources.c [moved from src/daemon/modules.c with 58% similarity]
src/daemon/sources.h [moved from src/daemon/modules.h with 80% similarity]
src/daemon/sources/conntrack.c [moved from src/daemon/modules/conntrack.c with 91% similarity]
src/daemon/sources/conntrack.h [moved from src/daemon/modules/conntrack.h with 89% similarity]
src/daemon/sources/contextswitches.c [moved from src/daemon/modules/contextswitches.c with 94% similarity]
src/daemon/sources/contextswitches.h [moved from src/daemon/modules/contextswitches.h with 87% similarity]
src/daemon/sources/loadavg.c [moved from src/daemon/modules/loadavg.c with 91% similarity]
src/daemon/sources/loadavg.h [moved from src/daemon/modules/loadavg.h with 89% similarity]

index f6866ce62c204fcd158f713b5a0693a824678562..cb466c3e69cea94731951329b9522198de96bc74 100644 (file)
@@ -111,18 +111,18 @@ dist_collectyd_SOURCES = \
        src/daemon/logging.c \
        src/daemon/logging.h \
        src/daemon/main.c \
-       src/daemon/module.c \
-       src/daemon/module.h \
-       src/daemon/modules.c \
-       src/daemon/modules.h \
-       src/daemon/modules/conntrack.c \
-       src/daemon/modules/conntrack.h \
-       src/daemon/modules/contextswitches.c \
-       src/daemon/modules/contextswitches.h \
-       src/daemon/modules/loadavg.c \
-       src/daemon/modules/loadavg.h \
        src/daemon/queue.c \
        src/daemon/queue.h \
+       src/daemon/source.c \
+       src/daemon/source.h \
+       src/daemon/sources.c \
+       src/daemon/sources.h \
+       src/daemon/sources/conntrack.c \
+       src/daemon/sources/conntrack.h \
+       src/daemon/sources/contextswitches.c \
+       src/daemon/sources/contextswitches.h \
+       src/daemon/sources/loadavg.c \
+       src/daemon/sources/loadavg.h \
        src/daemon/util.c \
        src/daemon/util.h
 
index 43adb4db480a814e631976acc32177e83deefe05..3c80bc05454d9bfa858ada2896797e71b9188e48 100644 (file)
@@ -30,9 +30,9 @@
 #include "daemon.h"
 #include "graphs.h"
 #include "graph-bus.h"
-#include "module.h"
-#include "modules.h"
 #include "queue.h"
+#include "source.h"
+#include "sources.h"
 
 struct collecty_daemon {
        collecty_ctx* ctx;
@@ -56,8 +56,8 @@ struct collecty_daemon {
        // Queue
        collecty_queue* queue;
 
-       // Modules
-       collecty_modules* modules;
+       // Sources
+       collecty_sources* sources;
 
        // Graphs
        collecty_graphs* graphs;
@@ -69,8 +69,8 @@ static int collecty_daemon_init(sd_event_source* source, void* data) {
 
        DEBUG(self->ctx, "Initializing daemon...\n");
 
-       // Initialize all modules
-       r = collecty_modules_create(&self->modules, self->ctx, self);
+       // Initialize all sources
+       r = collecty_sources_create(&self->sources, self->ctx, self);
        if (r < 0)
                return r;
 
@@ -93,10 +93,10 @@ static int collecty_daemon_exit(sd_event_source* source, void* data) {
                self->graphs = NULL;
        }
 
-       // Free all modules
-       if (self->modules) {
-               collecty_modules_unref(self->modules);
-               self->modules = NULL;
+       // Free all sources
+       if (self->sources) {
+               collecty_sources_unref(self->sources);
+               self->sources = NULL;
        }
 
        return 0;
@@ -188,8 +188,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->modules)
-               collecty_modules_unref(self->modules);
+       if (self->sources)
+               collecty_sources_unref(self->sources);
        if (self->graphs)
                collecty_graphs_unref(self->graphs);
        if (self->queue)
@@ -261,9 +261,9 @@ sd_event* collecty_daemon_loop(collecty_daemon* self) {
        return sd_event_ref(self->loop);
 }
 
-collecty_modules* collecty_daemon_get_modules(collecty_daemon* self) {
-       if (self->modules)
-               return collecty_modules_ref(self->modules);
+collecty_sources* collecty_daemon_get_sources(collecty_daemon* self) {
+       if (self->sources)
+               return collecty_sources_ref(self->sources);
 
        return NULL;
 }
@@ -300,12 +300,12 @@ ERROR:
 }
 
 int collecty_daemon_submit(collecty_daemon* self,
-               collecty_module* module, const char* object, const char* value) {
+               collecty_source* source, const char* object, const char* value) {
        // Log action
        DEBUG(self->ctx, "%s(%s) submitted: %s\n",
-               collecty_module_name(module), (object) ? object : "", value);
+               collecty_source_name(source), (object) ? object : "", value);
 
-       return collecty_queue_submit(self->queue, module, object, value);
+       return collecty_queue_submit(self->queue, source, object, value);
 }
 
 static int collecty_daemon_bus_version(sd_bus* bus, const char* path, const char* interface,
index 6505c62e0f9eb468746e922e2d40b6d17d603893..93d0e0a6bd39ece660d2875443c1b46e925f10bc 100644 (file)
@@ -28,8 +28,8 @@ typedef struct collecty_daemon collecty_daemon;
 #include "bus.h"
 #include "ctx.h"
 #include "graphs.h"
-#include "module.h"
-#include "modules.h"
+#include "source.h"
+#include "sources.h"
 
 int collecty_daemon_create(collecty_daemon** daemon, collecty_ctx* ctx);
 
@@ -37,13 +37,13 @@ collecty_daemon* collecty_daemon_ref(collecty_daemon* daemon);
 collecty_daemon* collecty_daemon_unref(collecty_daemon* daemon);
 
 sd_event* collecty_daemon_loop(collecty_daemon* self);
-collecty_modules* collecty_daemon_get_modules(collecty_daemon* self);
+collecty_sources* collecty_daemon_get_sources(collecty_daemon* self);
 collecty_graphs* collecty_daemon_get_graphs(collecty_daemon* self);
 
 int collecty_daemon_run(collecty_daemon* self);
 
 int collecty_daemon_submit(collecty_daemon* self,
-               collecty_module* module, const char* object, const char* value);
+               collecty_source* source, const char* object, const char* value);
 
 // Bus
 extern const collecty_bus_implementation daemon_bus_impl;
index 92f0889a4f258e35fec5094e387e2974e88f87ad..0f1e55e698a15586808c6e6f652ab63cc2976fa0 100644 (file)
@@ -165,37 +165,37 @@ char* collecty_graph_get_bus_path(collecty_graph* self) {
        return path;
 }
 
-int collecty_graph_require_module(collecty_graph* self,
+int collecty_graph_require_source(collecty_graph* self,
                collecty_args* args, const char* name, const char* object) {
-       collecty_modules* modules = NULL;
-       collecty_module* module = NULL;
+       collecty_sources* sources = NULL;
+       collecty_source* source = NULL;
        int r;
 
-       // Fetch all modules
-       modules = collecty_daemon_get_modules(self->daemon);
-       if (!modules) {
+       // Fetch all sources
+       sources = collecty_daemon_get_sources(self->daemon);
+       if (!sources) {
                r = -ENOTSUP;
                goto ERROR;
        }
 
-       // Fetch the module by its name
-       module = collecty_modules_get_by_name(modules, name);
-       if (!module) {
-               ERROR(self->ctx, "Could not find module '%s'\n", name);
+       // Fetch the source by its name
+       source = collecty_sources_get_by_name(sources, name);
+       if (!source) {
+               ERROR(self->ctx, "Could not find source '%s'\n", name);
                r = -ENOENT;
                goto ERROR;
        }
 
-       // Add the data of the module
-       r = collecty_module_render(module, args, object);
+       // Add the data of the source
+       r = collecty_source_render(source, args, object);
        if (r < 0)
                goto ERROR;
 
 ERROR:
-       if (modules)
-               collecty_modules_unref(modules);
-       if (module)
-               collecty_module_unref(module);
+       if (sources)
+               collecty_sources_unref(sources);
+       if (source)
+               collecty_source_unref(source);
 
        return r;
 }
index f9352149e622dce81e12c696024e4a8dfcd39911..c51ea2408148a15a840a4b2a82e2120da09e836d 100644 (file)
@@ -61,7 +61,7 @@ collecty_graph* collecty_graph_unref(collecty_graph* self);
 const char* collecty_graph_get_name(collecty_graph* self);
 char* collecty_graph_get_bus_path(collecty_graph* self);
 
-int collecty_graph_require_module(collecty_graph* self,
+int collecty_graph_require_source(collecty_graph* self,
        collecty_args* args, const char* name, const char* object);
 
 typedef struct collecty_graph_render_options {
index c258ff55a1a0ef7f51cdd066783dbdc29a94d115..16c4782ffdd5fefd550b7258814d1df16501f236 100644 (file)
@@ -40,8 +40,8 @@ static int loadavg_render(collecty_ctx* ctx,
                collecty_graph* graph, collecty_args* args, const char* object) {
        int r;
 
-       // This requires the loadavg module
-       r = collecty_graph_require_module(graph, args, "loadavg", object);
+       // This requires the loadavg source
+       r = collecty_graph_require_source(graph, args, "loadavg", object);
        if (r < 0)
                return r;
 
index bd1fd4c0a1616ed55eba90907c9d4dc83b262cdc..553944e09db18f9e28ebf6004a21bd8bbf92b328 100644 (file)
@@ -34,8 +34,8 @@
 struct collecty_queue_object {
        STAILQ_ENTRY(collecty_queue_object) nodes;
 
-       // Module
-       collecty_module* module;
+       // Source
+       collecty_source* source;
 
        // Object
        char* object;
@@ -94,8 +94,8 @@ static void collecty_queue_free_object(struct collecty_queue_object* o) {
                free(o->samples);
        }
 
-       if (o->module)
-               collecty_module_unref(o->module);
+       if (o->source)
+               collecty_source_unref(o->source);
        if (o->object)
                free(o->object);
        free(o);
@@ -190,12 +190,12 @@ collecty_queue* collecty_queue_unref(collecty_queue* self) {
 }
 
 static struct collecty_queue_object* collecty_queue_find_object(
-               collecty_queue* self, collecty_module* module, const char* object) {
+               collecty_queue* self, collecty_source* source, const char* object) {
        struct collecty_queue_object* o = NULL;
 
        STAILQ_FOREACH(o, &self->queue, nodes) {
-               // The module must match
-               if (o->module != module)
+               // The source must match
+               if (o->source != source)
                        continue;
 
                // If both objects are NULL we have a match
@@ -212,7 +212,7 @@ static struct collecty_queue_object* collecty_queue_find_object(
        return NULL;
 }
 
-static int collecty_queue_object_append_sample(collecty_queue* self, collecty_module* module,
+static int collecty_queue_object_append_sample(collecty_queue* self, collecty_source* source,
                const char* object, struct collecty_queue_object* o, const char* sample) {
        struct timeval t = {};
        char** samples = NULL;
@@ -247,7 +247,7 @@ static int collecty_queue_object_append_sample(collecty_queue* self, collecty_mo
        Submits a new reading into the queue
 */
 int collecty_queue_submit(collecty_queue* self,
-               collecty_module* module, const char* object, const char* sample) {
+               collecty_source* source, const char* object, const char* sample) {
        struct collecty_queue_object* o = NULL;
        int r;
 
@@ -256,17 +256,17 @@ int collecty_queue_submit(collecty_queue* self,
                return -EINVAL;
 
        // Check if we can append the sample
-       o = collecty_queue_find_object(self, module, object);
+       o = collecty_queue_find_object(self, source, object);
        if (o)
-               return collecty_queue_object_append_sample(self, module, object, o, sample);
+               return collecty_queue_object_append_sample(self, source, object, o, sample);
 
        // Allocate some memory
        o = calloc(1, sizeof(*o));
        if (!o)
                return -errno;
 
-       // Reference the module
-       o->module = collecty_module_ref(module);
+       // Reference the source
+       o->source = collecty_source_ref(source);
 
        // Store the object
        if (o->object) {
@@ -278,7 +278,7 @@ int collecty_queue_submit(collecty_queue* self,
        }
 
        // Store the sample
-       r = collecty_queue_object_append_sample(self, module, object, o, sample);
+       r = collecty_queue_object_append_sample(self, source, object, o, sample);
        if (r < 0)
                goto ERROR;
 
@@ -305,11 +305,11 @@ int collecty_queue_flush(collecty_queue* self) {
                if (!o)
                        break;
 
-               // Call the module to write its data
-               r = collecty_module_commit(o->module, o->object, o->num_samples, (const char**)o->samples);
+               // Call the source to write its data
+               r = collecty_source_commit(o->source, o->object, o->num_samples, (const char**)o->samples);
                if (r < 0) {
                        ERROR(self->ctx, "Failed to write samples for %s(%s): %s\n",
-                               collecty_module_name(o->module), (o->object) ? o->object : NULL, strerror(-r));
+                               collecty_source_name(o->source), (o->object) ? o->object : NULL, strerror(-r));
                }
 
                // Remove the object from the queue
index 9844c3eff45277ca73f42710d1df3aaf6c866bfe..1a813d3daeb5072d187bb414fe4373b9fd71de48 100644 (file)
@@ -25,7 +25,7 @@ typedef struct collecty_queue collecty_queue;
 
 #include "ctx.h"
 #include "daemon.h"
-#include "module.h"
+#include "source.h"
 
 int collecty_queue_create(collecty_queue** queue,
                collecty_ctx* ctx, collecty_daemon* daemon);
@@ -34,7 +34,7 @@ collecty_queue* collecty_queue_ref(collecty_queue* self);
 collecty_queue* collecty_queue_unref(collecty_queue* self);
 
 int collecty_queue_submit(collecty_queue* self,
-       collecty_module* module, const char* object, const char* sample);
+       collecty_source* source, const char* object, const char* sample);
 
 int collecty_queue_flush(collecty_queue* self);
 
similarity index 81%
rename from src/daemon/module.c
rename to src/daemon/source.c
index 707ddc8de175d456c3a2c4f075efe02ffbaf7c63..e4db4f19f83b018e18066bbbf9ec03a664dc8901 100644 (file)
@@ -32,7 +32,7 @@
 #include "args.h"
 #include "ctx.h"
 #include "daemon.h"
-#include "module.h"
+#include "source.h"
 #include "util.h"
 
 #define STEPSIZE 60 // seconds
@@ -63,7 +63,7 @@ static const collecty_rrd_rra default_rras[] = {
        { NULL },
 };
 
-struct collecty_module {
+struct collecty_source {
        collecty_ctx* ctx;
        int nrefs;
 
@@ -71,7 +71,7 @@ struct collecty_module {
        collecty_daemon* daemon;
 
        // Implementation
-       const collecty_module_impl* impl;
+       const collecty_source_impl* impl;
 
        // Event Loop
        sd_event* loop;
@@ -82,17 +82,17 @@ struct collecty_module {
        } events;
 };
 
-static int collecty_module_heartbeat(sd_event_source* source, uint64_t usec, void* data) {
-       collecty_module* self = data;
+static int collecty_source_heartbeat(sd_event_source* source, uint64_t usec, void* data) {
+       collecty_source* self = data;
        int r;
 
-       DEBUG(self->ctx, "Heartbeat called for %s\n", collecty_module_name(self));
+       DEBUG(self->ctx, "Heartbeat called for %s\n", collecty_source_name(self));
 
        // Call the collect method
        r = self->impl->collect(self->ctx, self);
        if (r < 0) {
                ERROR(self->ctx, "collect() failed for %s: %s\n",
-                       collecty_module_name(self), strerror(-r));
+                       collecty_source_name(self), strerror(-r));
        }
 
        // Arm the timer again
@@ -108,7 +108,7 @@ static int collecty_module_heartbeat(sd_event_source* source, uint64_t usec, voi
        return 0;
 }
 
-static int collecty_module_register_heartbeat(collecty_module* self) {
+static int collecty_source_register_heartbeat(collecty_source* self) {
        int r;
 
        // No need to do this if we don't have a collect method
@@ -117,7 +117,7 @@ static int collecty_module_register_heartbeat(collecty_module* self) {
 
        // Call the heartbeat function immediately
        r = sd_event_add_time_relative(self->loop, &self->events.heartbeat,
-                       CLOCK_MONOTONIC, 0, 0, collecty_module_heartbeat, self);
+                       CLOCK_MONOTONIC, 0, 0, collecty_source_heartbeat, self);
        if (r < 0) {
                ERROR(self->ctx, "Failed to register the heartbeat timer: %s\n", strerror(-r));
                return r;
@@ -126,24 +126,24 @@ static int collecty_module_register_heartbeat(collecty_module* self) {
        return 0;
 }
 
-static int collecty_module_init(collecty_module* self) {
+static int collecty_source_init(collecty_source* self) {
        int r;
 
        // Do nothing if there is no init function
        if (!self->impl->init)
                return 0;
 
-       // Initialize the module
+       // Initialize the source
        r = self->impl->init(self->ctx);
        if (r < 0) {
                ERROR(self->ctx, "Failed to initialize %s: %s\n",
-                       collecty_module_name(self), strerror(-r));
+                       collecty_source_name(self), strerror(-r));
        }
 
        return r;
 }
 
-static void collecty_module_free(collecty_module* self) {
+static void collecty_source_free(collecty_source* self) {
        if (self->impl->free)
                self->impl->free(self->ctx);
        if (self->events.heartbeat)
@@ -157,9 +157,9 @@ static void collecty_module_free(collecty_module* self) {
        free(self);
 }
 
-int collecty_module_create(collecty_module** module,
-               collecty_ctx* ctx, collecty_daemon* daemon, const collecty_module_impl* impl) {
-       collecty_module* self = NULL;
+int collecty_source_create(collecty_source** source,
+               collecty_ctx* ctx, collecty_daemon* daemon, const collecty_source_impl* impl) {
+       collecty_source* self = NULL;
        int r;
 
        // Allocate some memory
@@ -183,52 +183,52 @@ int collecty_module_create(collecty_module** module,
        self->impl = impl;
 
        // Register heartbeat
-       r = collecty_module_register_heartbeat(self);
+       r = collecty_source_register_heartbeat(self);
        if (r < 0)
                goto ERROR;
 
-       // Initialize the module
-       r = collecty_module_init(self);
+       // Initialize the source
+       r = collecty_source_init(self);
        if (r < 0)
                goto ERROR;
 
        // Return the pointer
-       *module = self;
+       *source = self;
        return 0;
 
 ERROR:
        if (self)
-               collecty_module_unref(self);
+               collecty_source_unref(self);
 
        return r;
 }
 
-collecty_module* collecty_module_ref(collecty_module* self) {
+collecty_source* collecty_source_ref(collecty_source* self) {
        ++self->nrefs;
        return self;
 }
 
-collecty_module* collecty_module_unref(collecty_module* self) {
+collecty_source* collecty_source_unref(collecty_source* self) {
        if (--self->nrefs > 0)
                return self;
 
-       collecty_module_free(self);
+       collecty_source_free(self);
        return NULL;
 }
 
-const char* collecty_module_name(collecty_module* self) {
+const char* collecty_source_name(collecty_source* self) {
        return self->impl->name;
 }
 
-#define collecty_module_path(module, object, path) \
-       __collecty_module_path(module, object, path, sizeof(path))
+#define collecty_source_path(source, object, path) \
+       __collecty_source_path(source, object, path, sizeof(path))
 
-static int __collecty_module_path(collecty_module* self,
+static int __collecty_source_path(collecty_source* self,
                const char* object, char* path, size_t length) {
        int r;
 
-       // Fetch the module name
-       const char* name = collecty_module_name(self);
+       // Fetch the source name
+       const char* name = collecty_source_name(self);
 
        if (object)
                r = snprintf(path, length, "%s/%s-%s.rrd", DATABASE_PATH, name, object);
@@ -243,9 +243,9 @@ static int __collecty_module_path(collecty_module* self,
 }
 
 /*
-       Called when a module has some data to submit
+       Called when a source has some data to submit
 */
-int collecty_module_submit(collecty_module* self,
+int collecty_source_submit(collecty_source* self,
                const char* object, const char* format, ...) {
        char value[2048];
        va_list args;
@@ -264,13 +264,13 @@ int collecty_module_submit(collecty_module* self,
        return collecty_daemon_submit(self->daemon, self, object, value);
 }
 
-static int collecty_module_create_database(collecty_module* self, const char* path) {
+static int collecty_source_create_database(collecty_source* 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);
+       DEBUG(self->ctx, "Creating database for %s at %s\n", collecty_source_name(self), path);
 
        // Allocate a new argument array
        r = collecty_args_create(&args, self->ctx);
@@ -333,14 +333,14 @@ ERROR:
 /*
        Called to write all collected samples to disk
 */
-int collecty_module_commit(collecty_module* self,
+int collecty_source_commit(collecty_source* self,
                const char* object, unsigned int num_samples, const char** samples) {
        struct stat st = {};
        char path[PATH_MAX];
        int r;
 
        // Make the path
-       r = collecty_module_path(self, object, path);
+       r = collecty_source_path(self, object, path);
        if (r < 0)
                return r;
 
@@ -349,7 +349,7 @@ int collecty_module_commit(collecty_module* self,
        if (r < 0) {
                switch (errno) {
                        case ENOENT:
-                               r = collecty_module_create_database(self, path);
+                               r = collecty_source_create_database(self, path);
                                if (r < 0)
                                        return r;
                                break;
@@ -370,12 +370,12 @@ int collecty_module_commit(collecty_module* self,
        return 0;
 }
 
-static int collecty_module_render_add_DEF(collecty_module* self,
+static int collecty_source_render_add_DEF(collecty_source* self,
                collecty_args* args, const char* path, const collecty_rrd_ds* ds, const char* object) {
        char field[NAME_MAX];
        int r;
 
-       // Append the object to the field name so that we can load multiple RRD of the same module
+       // Append the object to the field name so that we can load multiple RRD of the same source
        if (object) {
                r = snprintf(field, sizeof(field), "%s_%s", ds->field, object);
                if (r < 0)
@@ -414,18 +414,18 @@ static int collecty_module_render_add_DEF(collecty_module* self,
        return 0;
 }
 
-int collecty_module_render(collecty_module* self, collecty_args* args, const char* object) {
+int collecty_source_render(collecty_source* self, collecty_args* args, const char* object) {
        char path[PATH_MAX];
        int r;
 
        // Determine the path to the RRD file
-       r = collecty_module_path(self, object, path);
+       r = collecty_source_path(self, object, path);
        if (r < 0)
                return r;
 
        // Add all data sources
        for (const collecty_rrd_ds* ds = self->impl->rrd_dss; ds->field; ds++) {
-               r = collecty_module_render_add_DEF(self, args, path, ds, object);
+               r = collecty_source_render_add_DEF(self, args, path, ds, object);
                if (r < 0)
                        return r;
        }
similarity index 75%
rename from src/daemon/module.h
rename to src/daemon/source.h
index 8be7c723b13189450cb10018e16a0168db9968e0..feec90ad9fa1a5cef10f3586f2ad8dd8ddfeda9f 100644 (file)
 #                                                                             #
 #############################################################################*/
 
-#ifndef COLLECTY_MODULE_H
-#define COLLECTY_MODULE_H
+#ifndef COLLECTY_SOURCE_H
+#define COLLECTY_SOURCE_H
 
-typedef struct collecty_module collecty_module;
+typedef struct collecty_source collecty_source;
 
 #include "args.h"
 #include "ctx.h"
@@ -53,7 +53,7 @@ typedef struct collecty_rrd_rra {
        const char* rows;
 } collecty_rrd_rra;
 
-typedef struct collecty_module_impl {
+typedef struct collecty_source_impl {
        const char* name;
 
        // RRD Schema
@@ -67,24 +67,24 @@ typedef struct collecty_module_impl {
        int (*free)(collecty_ctx* ctx);
 
        // Collect
-       int (*collect)(collecty_ctx* ctx, collecty_module* module);
-} collecty_module_impl;
+       int (*collect)(collecty_ctx* ctx, collecty_source* source);
+} collecty_source_impl;
 
-int collecty_module_create(collecty_module** module,
-               collecty_ctx* ctx, collecty_daemon* daemon, const collecty_module_impl* impl);
+int collecty_source_create(collecty_source** source,
+               collecty_ctx* ctx, collecty_daemon* daemon, const collecty_source_impl* impl);
 
-collecty_module* collecty_module_ref(collecty_module* self);
-collecty_module* collecty_module_unref(collecty_module* self);
+collecty_source* collecty_source_ref(collecty_source* self);
+collecty_source* collecty_source_unref(collecty_source* self);
 
-const char* collecty_module_name(collecty_module* self);
+const char* collecty_source_name(collecty_source* self);
 
-int collecty_module_submit(collecty_module* self, const char* object,
+int collecty_source_submit(collecty_source* self, const char* object,
        const char* format, ...) __attribute__((format(printf, 3, 4)));
 
-int collecty_module_commit(collecty_module* self,
+int collecty_source_commit(collecty_source* self,
        const char* object, unsigned int num_samples, const char** samples);
 
-int collecty_module_render(collecty_module* self,
+int collecty_source_render(collecty_source* self,
        collecty_args* args, const char* object);
 
-#endif /* COLLECTY_MODULE_H */
+#endif /* COLLECTY_SOURCE_H */
similarity index 58%
rename from src/daemon/modules.c
rename to src/daemon/sources.c
index 6634cd0b1dfd8c5a3c23a3ede871c28773adefc5..8e5287c26c4982beea8996da8702bac4ad44464b 100644 (file)
 
 #include "ctx.h"
 #include "daemon.h"
-#include "module.h"
-#include "modules.h"
-
-// Load all modules
-#include "modules/conntrack.h"
-#include "modules/contextswitches.h"
-#include "modules/loadavg.h"
-
-// Register all modules
-static const collecty_module_impl* module_impls[] = {
-       &conntrack_module,
-       &contextswitches_module,
-       &loadavg_module,
+#include "source.h"
+#include "sources.h"
+
+// Load all sources
+#include "sources/conntrack.h"
+#include "sources/contextswitches.h"
+#include "sources/loadavg.h"
+
+// Register all sources
+static const collecty_source_impl* source_impls[] = {
+       &conntrack_source,
+       &contextswitches_source,
+       &loadavg_source,
        NULL,
 };
 
-struct collecty_modules {
+struct collecty_sources {
        collecty_ctx* ctx;
        int nrefs;
 
        // Daemon
        collecty_daemon* daemon;
 
-       // Modules
-       collecty_module** modules;
-       unsigned int num_modules;
+       // Sources
+       collecty_source** sources;
+       unsigned int num_sources;
 };
 
 
-static int collecty_modules_init(collecty_modules* self) {
-       collecty_module** modules = NULL;
-       collecty_module* module = NULL;
+static int collecty_sources_init(collecty_sources* self) {
+       collecty_source** sources = NULL;
+       collecty_source* source = NULL;
        int r;
 
-       // Initialize all modules
-       for (const collecty_module_impl** impl = module_impls; *impl; impl++) {
-               r = collecty_module_create(&module, self->ctx, self->daemon, *impl);
+       // Initialize all sources
+       for (const collecty_source_impl** impl = source_impls; *impl; impl++) {
+               r = collecty_source_create(&source, self->ctx, self->daemon, *impl);
                if (r < 0)
                        return r;
 
-               // Make space to store the module
-               modules = reallocarray(self->modules, self->num_modules + 1, sizeof(*self->modules));
-               if (!modules) {
+               // Make space to store the source
+               sources = reallocarray(self->sources, self->num_sources + 1, sizeof(*self->sources));
+               if (!sources) {
                        r = -errno;
                        goto ERROR;
                }
 
-               // Store a reference to the module in the array
-               modules[self->num_modules++] = collecty_module_ref(module);
+               // Store a reference to the source in the array
+               sources[self->num_sources++] = collecty_source_ref(source);
 
                // Replace the array
-               self->modules = modules;
+               self->sources = sources;
 
-               // Unref the module
-               collecty_module_unref(module);
-               module = NULL;
+               // Unref the source
+               collecty_source_unref(source);
+               source = NULL;
        }
 
        return 0;
 
 ERROR:
-       if (module)
-               collecty_module_unref(module);
+       if (source)
+               collecty_source_unref(source);
 
        return r;
 }
 
-static void collecty_modules_free(collecty_modules* self) {
-       if (self->modules) {
-               for (unsigned int i = 0; i < self->num_modules; i++)
-                       collecty_module_unref(self->modules[i]);
-               free(self->modules);
+static void collecty_sources_free(collecty_sources* self) {
+       if (self->sources) {
+               for (unsigned int i = 0; i < self->num_sources; i++)
+                       collecty_source_unref(self->sources[i]);
+               free(self->sources);
        }
        if (self->daemon)
                collecty_daemon_unref(self->daemon);
@@ -104,9 +104,9 @@ static void collecty_modules_free(collecty_modules* self) {
        free(self);
 }
 
-int collecty_modules_create(collecty_modules** modules,
+int collecty_sources_create(collecty_sources** sources,
                collecty_ctx* ctx, collecty_daemon* daemon) {
-       collecty_modules* self = NULL;
+       collecty_sources* self = NULL;
        int r;
 
        // Allocate some memory
@@ -123,48 +123,48 @@ int collecty_modules_create(collecty_modules** modules,
        // Store a reference to the daemon
        self->daemon = collecty_daemon_ref(daemon);
 
-       // Setup all modules
-       r = collecty_modules_init(self);
+       // Setup all sources
+       r = collecty_sources_init(self);
        if (r < 0)
                goto ERROR;
 
        // Return the pointer
-       *modules = self;
+       *sources = self;
        return 0;
 
 ERROR:
        if (self)
-               collecty_modules_unref(self);
+               collecty_sources_unref(self);
 
        return r;
 }
 
-collecty_modules* collecty_modules_ref(collecty_modules* self) {
+collecty_sources* collecty_sources_ref(collecty_sources* self) {
        ++self->nrefs;
        return self;
 }
 
-collecty_modules* collecty_modules_unref(collecty_modules* self) {
+collecty_sources* collecty_sources_unref(collecty_sources* self) {
        if (--self->nrefs > 0)
                return self;
 
-       collecty_modules_free(self);
+       collecty_sources_free(self);
        return NULL;
 }
 
-collecty_module* collecty_modules_get_by_name(collecty_modules* self, const char* name) {
+collecty_source* collecty_sources_get_by_name(collecty_sources* self, const char* name) {
        const char* n = NULL;
 
-       // Iterate over all modules to find a match
-       for (unsigned int i = 0; i < self->num_modules; i++) {
+       // Iterate over all sources to find a match
+       for (unsigned int i = 0; i < self->num_sources; i++) {
                // Fetch the name
-               n = collecty_module_name(self->modules[i]);
+               n = collecty_source_name(self->sources[i]);
                if (!n)
                        continue;
 
                // Return the object if the name matches
                if (strcmp(name, n) == 0)
-                       return collecty_module_ref(self->modules[i]);
+                       return collecty_source_ref(self->sources[i]);
        }
 
        return NULL;
similarity index 80%
rename from src/daemon/modules.h
rename to src/daemon/sources.h
index d4aa8c413a7630289cfedd84752cee3749ad2a1e..79dc2c3b8c93ed7608bdbe4ae7193f14873cdca8 100644 (file)
 #                                                                             #
 #############################################################################*/
 
-#ifndef COLLECTY_MODULES_H
-#define COLLECTY_MODULES_H
+#ifndef COLLECTY_SOURCES_H
+#define COLLECTY_SOURCES_H
 
-typedef struct collecty_modules collecty_modules;
+typedef struct collecty_sources collecty_sources;
 
 #include "ctx.h"
 #include "daemon.h"
+#include "source.h"
 
-int collecty_modules_create(collecty_modules** modules,
+int collecty_sources_create(collecty_sources** sources,
        collecty_ctx* ctx, collecty_daemon* daemon);
 
-collecty_modules* collecty_modules_ref(collecty_modules* self);
-collecty_modules* collecty_modules_unref(collecty_modules* self);
+collecty_sources* collecty_sources_ref(collecty_sources* self);
+collecty_sources* collecty_sources_unref(collecty_sources* self);
 
-collecty_module* collecty_modules_get_by_name(collecty_modules* self, const char* name);
+collecty_source* collecty_sources_get_by_name(collecty_sources* self, const char* name);
 
-#endif /* COLLECTY_MODULES_H */
+#endif /* COLLECTY_SOURCES_H */
similarity index 91%
rename from src/daemon/modules/conntrack.c
rename to src/daemon/sources/conntrack.c
index dda367a63002015f5133054e43dc50c169fc4d0a..e3dd4186ef599134912fc9ca4e482e62191690fc 100644 (file)
 #include <string.h>
 
 #include "../ctx.h"
-#include "../module.h"
+#include "../source.h"
 #include "../util.h"
 #include "conntrack.h"
 
-static int conntrack_collect(collecty_ctx* ctx, collecty_module* module) {
+static int conntrack_collect(collecty_ctx* ctx, collecty_source* source) {
        uint64_t count = 0;
        uint64_t max = 0;
        int r;
@@ -47,10 +47,10 @@ static int conntrack_collect(collecty_ctx* ctx, collecty_module* module) {
        }
 
        // Submit the values
-       return collecty_module_submit(module, NULL, "%" PRIu64 ":%" PRIu64, count, max);
+       return collecty_source_submit(source, NULL, "%" PRIu64 ":%" PRIu64, count, max);
 }
 
-const collecty_module_impl conntrack_module = {
+const collecty_source_impl conntrack_source = {
        .name    = "conntrack",
 
        // RRD Data Sources
similarity index 89%
rename from src/daemon/modules/conntrack.h
rename to src/daemon/sources/conntrack.h
index 68d555ee91bbd351e1edba565b91575669774815..8ed7180fad2557a6169205df49e07e6311a5ec33 100644 (file)
 #                                                                             #
 #############################################################################*/
 
-#ifndef COLLECTY_MODULE_CONNTRACK_H
-#define COLLECTY_MODULE_CONNTRACK_H
+#ifndef COLLECTY_SOURCE_CONNTRACK_H
+#define COLLECTY_SOURCE_CONNTRACK_H
 
-#include "../module.h"
+#include "../source.h"
 
-extern const collecty_module_impl conntrack_module;
+extern const collecty_source_impl conntrack_source;
 
-#endif /* COLLECTY_MODULE_CONNTRACK_H */
+#endif /* COLLECTY_SOURCE_CONNTRACK_H */
similarity index 94%
rename from src/daemon/modules/contextswitches.c
rename to src/daemon/sources/contextswitches.c
index bb3cf2a975c594254010b1e7454b2e08f64f4c57..6dd891f530a7113416a20d4a41fd2f117095f9ff 100644 (file)
@@ -25,7 +25,7 @@
 #include <unistd.h>
 
 #include "../ctx.h"
-#include "../module.h"
+#include "../source.h"
 #include "contextswitches.h"
 
 static int perf_event_open(struct perf_event_attr* hw_event,
@@ -88,7 +88,7 @@ static int contextswitches_free(collecty_ctx* ctx) {
        return 0;
 }
 
-static int contextswitches_collect(collecty_ctx* ctx, collecty_module* module) {
+static int contextswitches_collect(collecty_ctx* ctx, collecty_source* source) {
        long long total = 0;
        uint64_t count = 0;
        int fd = -EBADF;
@@ -114,10 +114,10 @@ static int contextswitches_collect(collecty_ctx* ctx, collecty_module* module) {
        }
 
        // Submit the values
-       return collecty_module_submit(module, NULL, "%lld", total);
+       return collecty_source_submit(source, NULL, "%lld", total);
 }
 
-const collecty_module_impl contextswitches_module = {
+const collecty_source_impl contextswitches_source = {
        .name    = "contextswitches",
 
        // RRD Data Sources
similarity index 87%
rename from src/daemon/modules/contextswitches.h
rename to src/daemon/sources/contextswitches.h
index 9753c7adccf1bf8a84bf65e35df962d1e4991d1d..a5fa2bbaba7653261757ad5bc6e3e92d25ec62cd 100644 (file)
 #                                                                             #
 #############################################################################*/
 
-#ifndef COLLECTY_MODULE_CONTEXTSWITCHES_H
-#define COLLECTY_MODULE_CONTEXTSWITCHES_H
+#ifndef COLLECTY_SOURCE_CONTEXTSWITCHES_H
+#define COLLECTY_SOURCE_CONTEXTSWITCHES_H
 
-#include "../module.h"
+#include "../source.h"
 
-extern const collecty_module_impl contextswitches_module;
+extern const collecty_source_impl contextswitches_source;
 
-#endif /* COLLECTY_MODULE_CONTEXTSWITCHES_H */
+#endif /* COLLECTY_SOURCE_CONTEXTSWITCHES_H */
similarity index 91%
rename from src/daemon/modules/loadavg.c
rename to src/daemon/sources/loadavg.c
index 85794057b4a0a82ae9be12aba82f0def5f94faad..b14d16f628b4b7d91fe3ef6b0aae807683ab6d84 100644 (file)
 #include <stdlib.h>
 
 #include "../ctx.h"
-#include "../module.h"
+#include "../source.h"
 #include "loadavg.h"
 
-static int loadavg_collect(collecty_ctx* ctx, collecty_module* module) {
+static int loadavg_collect(collecty_ctx* ctx, collecty_source* source) {
        double loadavg[3];
        int r;
 
@@ -34,11 +34,11 @@ static int loadavg_collect(collecty_ctx* ctx, collecty_module* module) {
                return r;
 
        // Submit the values
-       return collecty_module_submit(module, NULL,
+       return collecty_source_submit(source, NULL,
                "%f:%f:%f", loadavg[0], loadavg[1], loadavg[2]);
 }
 
-const collecty_module_impl loadavg_module = {
+const collecty_source_impl loadavg_source = {
        .name    = "loadavg",
 
        // RRD Data Sources
similarity index 89%
rename from src/daemon/modules/loadavg.h
rename to src/daemon/sources/loadavg.h
index 79083f7c567616fa1698ae1ee8c3bd766da13afe..f26ef97593f0f794c78f92189c7f035245f25ba4 100644 (file)
 #                                                                             #
 #############################################################################*/
 
-#ifndef COLLECTY_MODULE_LOADAVG_H
-#define COLLECTY_MODULE_LOADAVG_H
+#ifndef COLLECTY_SOURCE_LOADAVG_H
+#define COLLECTY_SOURCE_LOADAVG_H
 
-#include "../module.h"
+#include "../source.h"
 
-extern const collecty_module_impl loadavg_module;
+extern const collecty_source_impl loadavg_source;
 
-#endif /* COLLECTY_MODULE_LOADAVG_H */
+#endif /* COLLECTY_SOURCE_LOADAVG_H */