--- /dev/null
+/*#############################################################################
+# #
+# 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,
+};
--- /dev/null
+/*#############################################################################
+# #
+# 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 */
// 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 */