From: Michael Tremer Date: Sun, 28 Sep 2025 11:14:06 +0000 (+0000) Subject: modules: Add the conntrack module X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6ad9e65356140209bc8b730e2f63bdd0405f938c;p=collecty.git modules: Add the conntrack module Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 330b22a..5eb9257 100644 --- a/Makefile.am +++ b/Makefile.am @@ -102,6 +102,8 @@ dist_collectyd_SOURCES = \ 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 \ diff --git a/src/daemon/modules.c b/src/daemon/modules.c index da13f85..c9e2698 100644 --- a/src/daemon/modules.c +++ b/src/daemon/modules.c @@ -28,11 +28,13 @@ #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_methods* modules[] = { + &conntrack_module, &contextswitches_module, &loadavg_module, NULL, diff --git a/src/daemon/modules/conntrack.c b/src/daemon/modules/conntrack.c new file mode 100644 index 0000000..0ecb5cd --- /dev/null +++ b/src/daemon/modules/conntrack.c @@ -0,0 +1,65 @@ +/*############################################################################# +# # +# collecty - A system statistics collection daemon for IPFire # +# Copyright (C) 2025 IPFire Development Team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +#############################################################################*/ + +#include + +#include "../ctx.h" +#include "../module.h" +#include "../util.h" +#include "conntrack.h" + +static int conntrack_collect(collecty_ctx* ctx, collecty_module* module) { + uint64_t count = 0; + uint64_t max = 0; + int r; + + // Read the total number of connections + r = collecty_file_read_uint64("/proc/sys/net/netfilter/nf_conntrack_count", &count); + if (r < 0) { + ERROR(ctx, "Failed to read %s: %s\n", + "/proc/sys/net/netfilter/nf_conntrack_count", strerror(-r)); + return r; + } + + // Read the maximum number of connections + r = collecty_file_read_uint64("/proc/sys/net/netfilter/nf_conntrack_max", &max); + if (r < 0) { + ERROR(ctx, "Failed to read %s: %s\n", + "/proc/sys/net/netfilter/nf_conntrack_max", strerror(-r)); + return r; + } + + // Submit the values + return collecty_module_submit(module, NULL, "%" PRIu64 ":%" PRIu64, count, max); +} + +const collecty_module_methods conntrack_module = { + .name = "conntrack", + + // RRD Data Sources + .rrd_dss = { + { "count", "GAUGE", 0, -1, }, + { "max", "GAUGE", 0, -1, }, + { NULL }, + }, + + // Methods + .collect = conntrack_collect, +}; diff --git a/src/daemon/modules/conntrack.h b/src/daemon/modules/conntrack.h new file mode 100644 index 0000000..60bdc07 --- /dev/null +++ b/src/daemon/modules/conntrack.h @@ -0,0 +1,28 @@ +/*############################################################################# +# # +# collecty - A system statistics collection daemon for IPFire # +# Copyright (C) 2025 IPFire Development Team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +#############################################################################*/ + +#ifndef COLLECTY_MODULE_CONNTRACK_H +#define COLLECTY_MODULE_CONNTRACK_H + +#include "../module.h" + +extern const collecty_module_methods conntrack_module; + +#endif /* COLLECTY_MODULE_CONNTRACK_H */