]> git.ipfire.org Git - collecty.git/commitdiff
graphs: Add a conntrack graph
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 3 Oct 2025 12:46:08 +0000 (12:46 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 3 Oct 2025 12:46:08 +0000 (12:46 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/daemon/colors.h
src/daemon/graphs.c
src/daemon/graphs/conntrack.c [new file with mode: 0644]
src/daemon/graphs/conntrack.h [new file with mode: 0644]
src/daemon/graphs/graph.h

index ef2e564d7e8fb23ff57e511300dab38356910b1e..956e75892e63b02728bb8afe6f4fe0d4b03b0991 100644 (file)
@@ -105,6 +105,8 @@ dist_collectyd_SOURCES = \
        src/daemon/graph-bus.h \
        src/daemon/graphs.c \
        src/daemon/graphs.h \
+       src/daemon/graphs/conntrack.c \
+       src/daemon/graphs/conntrack.h \
        src/daemon/graphs/graph.h \
        src/daemon/graphs/loadavg.c \
        src/daemon/graphs/loadavg.h \
index 363d9f28f51b0a982a6d3449fe7e941fcb68d07d..8994377e265379427a0eef5ef6715ea68f31a451 100644 (file)
 #define BLUE                   "#2196f3"
 #define LIGHT_BLUE             "#03a9f4"
 
+/*
+       Define some colours with a special meaning...
+*/
+
+// Limit - When there is a ceiling to resource usage
+#define LIMIT                  RED
+
 // Macro to make colours transparent
 #define COLOR_WITH_ALPHA(base, alpha) base alpha
 
index 801d72fc41712256eccaf689bda0f591385fd635..02bb745723616088a83edf4005ffe2255cce5da1 100644 (file)
 #include "graphs.h"
 
 // Load all graphs
+#include "graphs/conntrack.h"
 #include "graphs/loadavg.h"
 
 // Register all graphs
 static const collecty_graph_impl* graph_impls[] = {
+       &conntrack_graph,
        &loadavg_graph,
        NULL,
 };
diff --git a/src/daemon/graphs/conntrack.c b/src/daemon/graphs/conntrack.c
new file mode 100644 (file)
index 0000000..3eaf1ba
--- /dev/null
@@ -0,0 +1,134 @@
+/*#############################################################################
+#                                                                             #
+# 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 <limits.h>
+
+#include "graph.h"
+#include "conntrack.h"
+
+// Set some colors
+#define COLOR_LOAD15   RED
+#define COLOR_LOAD5            ORANGE
+#define COLOR_LOAD1            YELLOW
+
+static int conntrack_title(collecty_ctx* ctx,
+               collecty_graph* graph, const char* object, char** title) {
+       return collecty_format_title(title, "%s", _("Connection Tracking Table"));
+}
+
+static int conntrack_vlabel(collecty_ctx* ctx,
+               collecty_graph* graph, const char* object, char** title) {
+       return collecty_format_title(title, "%s", _("Entries"));
+}
+
+static int conntrack_render(collecty_ctx* ctx,
+               collecty_graph* graph, collecty_args* args, const char* object) {
+       int r;
+
+       // This requires the conntrack source
+       r = collecty_graph_require_source(graph, args, "conntrack", object);
+       if (r < 0)
+               return r;
+
+       // Draw the maximum line
+       r = collecty_args_push(args,
+                       DRAW_WITH_LABEL("LINE1", "max", LIMIT, DASHES SKIPSCALE), _("Limit"));
+       if (r < 0)
+               return r;
+
+       // Show the current limit
+       r = collecty_args_push(args, PRINT_LARGE_INTEGER("max_cur"));
+       if (r < 0)
+               return r;
+
+       // Add an empty column
+       r = collecty_args_push(args, PRINT_NOTHING);
+       if (r < 0)
+               return r;
+
+       // Add an empty column
+       r = collecty_args_push(args, PRINT_NOTHING);
+       if (r < 0)
+               return r;
+
+       // Add an empty column
+       r = collecty_args_push(args, PRINT_NOTHING EOL);
+       if (r < 0)
+               return r;
+
+       // Draw the main area
+       r = collecty_args_push(args, DRAW_WITH_LABEL("AREA", "count", GREEN), _("Entries"));
+       if (r < 0)
+               return r;
+
+       r = collecty_args_push(args, PRINT_LARGE_INTEGER("count_cur"));
+       if (r < 0)
+               return r;
+
+       r = collecty_args_push(args, PRINT_LARGE_INTEGER("count_avg"));
+       if (r < 0)
+               return r;
+
+       r = collecty_args_push(args, PRINT_LARGE_INTEGER("count_min"));
+       if (r < 0)
+               return r;
+
+       r = collecty_args_push(args, PRINT_LARGE_INTEGER("count_max") EOL);
+       if (r < 0)
+               return r;
+
+       // Add an empty line
+       r = collecty_args_push(args, EMPTY_COLUMN);
+       if (r < 0)
+               return r;
+
+       // Add the headline for the "Current" column
+       r = collecty_args_push(args, HEADER, _("Current"));
+       if (r < 0)
+               return r;
+
+       // Add the headline for the "Average" column
+       r = collecty_args_push(args, HEADER, _("Average"));
+       if (r < 0)
+               return r;
+
+       // Add the headline for the "Minimum" column
+       r = collecty_args_push(args, HEADER, _("Minimum"));
+       if (r < 0)
+               return r;
+
+       // Add the headline for the "Maximum" column
+       r = collecty_args_push(args, HEADER EOL, _("Maximum"));
+       if (r < 0)
+               return r;
+
+       return 0;
+}
+
+const collecty_graph_impl conntrack_graph = {
+       .name    = "Conntrack",
+       .render  = conntrack_render,
+       .title   = conntrack_title,
+       .vlabel  = conntrack_vlabel,
+
+       // Limits
+       .lower_limit = 0,
+       .upper_limit = LONG_MAX,
+};
diff --git a/src/daemon/graphs/conntrack.h b/src/daemon/graphs/conntrack.h
new file mode 100644 (file)
index 0000000..45e0619
--- /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_GRAPH_CONNTRACK_H
+#define COLLECTY_GRAPH_CONNTRACK_H
+
+#include "../graph.h"
+
+extern const collecty_graph_impl conntrack_graph;
+
+#endif /* COLLECTY_GRAPH_CONNTRACK_H */
index ad299aa3d86c8e0950e97205c5f644b7c1fb1693..dabbfa5297fecda02b20c88fc774105bdadef1bc 100644 (file)
 
 // A column is exactly 16 characters wide
 #define COLUMN                 "%16s"
+#define INTEGER                        "%%16.0lf"
+#define LARGE_INTEGER  "%%14.0lf %%s"
 #define FLOAT                  "%%14.2lf"
+#define LARGE_FLOAT            "%%12.2lf %%s"
 
 // Macro to terminate a line
 #define EOL                            "\\j"
 
 // Draw a LINE, AREA, etc.
-#define DRAW(what, field, color) what ":" field color
-#define DRAW_WITH_LABEL(what, field, color) DRAW(what, field, color) ":" LABEL
+#define DRAW(what, field, color, ...) \
+       what ":" field color __VA_ARGS__
+
+#define DRAW_WITH_LABEL(what, field, color, ...) \
+       DRAW(what, field, color) ":" LABEL __VA_ARGS__
+
+// Modifiers for lines
+#define DASHES                 ":dashes"
+#define SKIPSCALE              ":skipscale"
 
 // Add something to the legend of the graph
-#define PRINT_FLOAT(field) "GPRINT:" field ":" FLOAT
+#define PRINT(field, ...)                      "GPRINT:" field ":" __VA_ARGS__
+#define PRINT_NOTHING                          "COMMENT:                "
+#define PRINT_INTEGER(field)           PRINT(field, INTEGER)
+#define PRINT_LARGE_INTEGER(field)     PRINT(field, LARGE_INTEGER)
+#define PRINT_FLOAT(field)                     PRINT(field, FLOAT)
+#define PRINT_LARGE_FLOAT(field)       PRINT(field, LARGE_FLOAT)
 
 #endif /* COLLECTY_GRAPHS_GRAPH_H */