From: Michael Tremer Date: Fri, 3 Oct 2025 11:31:44 +0000 (+0000) Subject: daemon: Rename modules to sources X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2d11496fc48eddcbcd5aa5140622ac25ee2c0b0d;p=collecty.git daemon: Rename modules to sources 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 --- diff --git a/Makefile.am b/Makefile.am index f6866ce..cb466c3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c index 43adb4d..3c80bc0 100644 --- a/src/daemon/daemon.c +++ b/src/daemon/daemon.c @@ -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, diff --git a/src/daemon/daemon.h b/src/daemon/daemon.h index 6505c62..93d0e0a 100644 --- a/src/daemon/daemon.h +++ b/src/daemon/daemon.h @@ -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; diff --git a/src/daemon/graph.c b/src/daemon/graph.c index 92f0889..0f1e55e 100644 --- a/src/daemon/graph.c +++ b/src/daemon/graph.c @@ -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; } diff --git a/src/daemon/graph.h b/src/daemon/graph.h index f935214..c51ea24 100644 --- a/src/daemon/graph.h +++ b/src/daemon/graph.h @@ -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 { diff --git a/src/daemon/graphs/loadavg.c b/src/daemon/graphs/loadavg.c index c258ff5..16c4782 100644 --- a/src/daemon/graphs/loadavg.c +++ b/src/daemon/graphs/loadavg.c @@ -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; diff --git a/src/daemon/queue.c b/src/daemon/queue.c index bd1fd4c..553944e 100644 --- a/src/daemon/queue.c +++ b/src/daemon/queue.c @@ -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 diff --git a/src/daemon/queue.h b/src/daemon/queue.h index 9844c3e..1a813d3 100644 --- a/src/daemon/queue.h +++ b/src/daemon/queue.h @@ -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); diff --git a/src/daemon/module.c b/src/daemon/source.c similarity index 81% rename from src/daemon/module.c rename to src/daemon/source.c index 707ddc8..e4db4f1 100644 --- a/src/daemon/module.c +++ b/src/daemon/source.c @@ -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; } diff --git a/src/daemon/module.h b/src/daemon/source.h similarity index 75% rename from src/daemon/module.h rename to src/daemon/source.h index 8be7c72..feec90a 100644 --- a/src/daemon/module.h +++ b/src/daemon/source.h @@ -18,10 +18,10 @@ # # #############################################################################*/ -#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 */ diff --git a/src/daemon/modules.c b/src/daemon/sources.c similarity index 58% rename from src/daemon/modules.c rename to src/daemon/sources.c index 6634cd0..8e5287c 100644 --- a/src/daemon/modules.c +++ b/src/daemon/sources.c @@ -24,78 +24,78 @@ #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; diff --git a/src/daemon/modules.h b/src/daemon/sources.h similarity index 80% rename from src/daemon/modules.h rename to src/daemon/sources.h index d4aa8c4..79dc2c3 100644 --- a/src/daemon/modules.h +++ b/src/daemon/sources.h @@ -18,20 +18,21 @@ # # #############################################################################*/ -#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 */ diff --git a/src/daemon/modules/conntrack.c b/src/daemon/sources/conntrack.c similarity index 91% rename from src/daemon/modules/conntrack.c rename to src/daemon/sources/conntrack.c index dda367a..e3dd418 100644 --- a/src/daemon/modules/conntrack.c +++ b/src/daemon/sources/conntrack.c @@ -21,11 +21,11 @@ #include #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 diff --git a/src/daemon/modules/conntrack.h b/src/daemon/sources/conntrack.h similarity index 89% rename from src/daemon/modules/conntrack.h rename to src/daemon/sources/conntrack.h index 68d555e..8ed7180 100644 --- a/src/daemon/modules/conntrack.h +++ b/src/daemon/sources/conntrack.h @@ -18,11 +18,11 @@ # # #############################################################################*/ -#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 */ diff --git a/src/daemon/modules/contextswitches.c b/src/daemon/sources/contextswitches.c similarity index 94% rename from src/daemon/modules/contextswitches.c rename to src/daemon/sources/contextswitches.c index bb3cf2a..6dd891f 100644 --- a/src/daemon/modules/contextswitches.c +++ b/src/daemon/sources/contextswitches.c @@ -25,7 +25,7 @@ #include #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 diff --git a/src/daemon/modules/contextswitches.h b/src/daemon/sources/contextswitches.h similarity index 87% rename from src/daemon/modules/contextswitches.h rename to src/daemon/sources/contextswitches.h index 9753c7a..a5fa2bb 100644 --- a/src/daemon/modules/contextswitches.h +++ b/src/daemon/sources/contextswitches.h @@ -18,11 +18,11 @@ # # #############################################################################*/ -#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 */ diff --git a/src/daemon/modules/loadavg.c b/src/daemon/sources/loadavg.c similarity index 91% rename from src/daemon/modules/loadavg.c rename to src/daemon/sources/loadavg.c index 8579405..b14d16f 100644 --- a/src/daemon/modules/loadavg.c +++ b/src/daemon/sources/loadavg.c @@ -21,10 +21,10 @@ #include #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 diff --git a/src/daemon/modules/loadavg.h b/src/daemon/sources/loadavg.h similarity index 89% rename from src/daemon/modules/loadavg.h rename to src/daemon/sources/loadavg.h index 79083f7..f26ef97 100644 --- a/src/daemon/modules/loadavg.h +++ b/src/daemon/sources/loadavg.h @@ -18,11 +18,11 @@ # # #############################################################################*/ -#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 */