]> git.ipfire.org Git - collecty.git/commitdiff
modules: Add the conntrack module
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 28 Sep 2025 11:14:06 +0000 (11:14 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 28 Sep 2025 11:14:06 +0000 (11:14 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/daemon/modules.c
src/daemon/modules/conntrack.c [new file with mode: 0644]
src/daemon/modules/conntrack.h [new file with mode: 0644]

index 330b22aec3a14952bf964376454eb16b2d42f19b..5eb9257113648ec86606b6f6d4f3d9156b4f03cf 100644 (file)
@@ -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 \
index da13f85d3dc2517f74cb9da4dd1eb43d93c16eb9..c9e2698f89e454d91c14335010e61afd0a3146f0 100644 (file)
 #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 (file)
index 0000000..0ecb5cd
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#include <string.h>
+
+#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 (file)
index 0000000..60bdc07
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#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 */