]> git.ipfire.org Git - oddments/collecty.git/commitdiff
graphs: Add bandwidth graphs for hostapd stations
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 21 Oct 2025 13:37:44 +0000 (13:37 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 21 Oct 2025 13:37:44 +0000 (13:37 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/daemon/graphs.c
src/daemon/graphs/graph.h
src/daemon/graphs/hostapd-station-bandwidth.c [new file with mode: 0644]
src/daemon/graphs/hostapd-station-bandwidth.h [new file with mode: 0644]

index 88fe9c0751cb67a8d77920e5241cdd6798a3361b..005ffd61d4c99c09d765033c4fe12eb0d0c1c6ee 100644 (file)
@@ -117,6 +117,8 @@ dist_telemetryd_SOURCES = \
        src/daemon/graphs/contextswitches.c \
        src/daemon/graphs/contextswitches.h \
        src/daemon/graphs/graph.h \
+       src/daemon/graphs/hostapd-station-bandwidth.c \
+       src/daemon/graphs/hostapd-station-bandwidth.h \
        src/daemon/graphs/hostapd-station-signal.c \
        src/daemon/graphs/hostapd-station-signal.h \
        src/daemon/graphs/loadavg.c \
index 29bcc5266f8b6aacc77182aee7c5c5ae68b26927..a101c91f431c9002b83c6a5b48e15cbfc01f0b87 100644 (file)
@@ -30,6 +30,7 @@
 // Load all graphs
 #include "graphs/conntrack.h"
 #include "graphs/contextswitches.h"
+#include "graphs/hostapd-station-bandwidth.h"
 #include "graphs/hostapd-station-signal.h"
 #include "graphs/loadavg.h"
 #include "graphs/memory.h"
@@ -40,6 +41,7 @@
 static const td_graph_impl* graph_impls[] = {
        &conntrack_graph,
        &contextswitches_graph,
+       &hostapd_station_bandwidth_graph,
        &hostapd_station_signal_graph,
        &loadavg_graph,
        &memory_graph,
index cc2ab8fa9097f59e7279564befd691207a66fe05..b175314291c375a4ac14ed6c3b754dff7a4ef14a 100644 (file)
@@ -55,6 +55,7 @@
 #define FLOAT                  "%%14.2lf"
 #define FLOAT_WITH_UNIT "%%10.2lf %3s"
 #define LARGE_FLOAT            "%%14.2lf %%s"
+#define BPS                            "%%9.2lf %%s%3s"
 
 // Macro to terminate a line
 #define EOL                            "\\j"
 #define FIELD_PERCENT(field)                           field "_p"
 #define FIELD_INF(field)                                       field "_inf"
 #define FIELD_NEGINF(field)                                    field "_neginf"
+#define FIELD_BITS(field)                                      field "_bits"
 
 #define VALUE_CURRENT(args, field, object)     SCRIPT(args, "VDEF:" FIELD_CURRENT(FIELD) "=" FIELD ",LAST", FIELD_AND_OBJECT(field, object), FIELD_AND_OBJECT(field, object))
 #define VALUE_AVERAGE(args, field, object)     SCRIPT(args, "VDEF:" FIELD_AVERAGE(FIELD) "=" FIELD ",AVERAGE", FIELD_AND_OBJECT(field, object), FIELD_AND_OBJECT(field, object))
                VALUE_ALL(args, difference, object); \
        } while (0)
 
+#define COMPUTE_MULTIPLY(args, product, object1, factor1, object2, factor2) \
+       do { \
+               COMPUTE_CDEF(args, FIELD "=" FIELD "," TOSTRING(factor2) ",*", \
+                       FIELD_AND_OBJECT(product, object1), \
+                       FIELD_AND_OBJECT(factor1, object2) \
+               ); \
+               VALUE_ALL(args, product, object1); \
+       } while (0)
+
+// Converts bytes to bits
+#define COMPUTE_BITS(args, bits, object, bytes)        \
+       COMPUTE_MULTIPLY(args, bits, object, bytes, object, 8)
+
 #define COMPUTE_DIVIDE(args, fraction, object1, dividend, object2, divisor) \
        do { \
                COMPUTE_CDEF(args, FIELD "=" FIELD "," TOSTRING(divisor) ",/", \
                ); \
        } while (0)
 
+/*
+       This draws a bandwidth graph
+*/
+#define DRAW_BANDWIDTH(args, object, rx_bytes, tx_bytes) \
+       do { \
+               DRAW_BANDWIDTH_INCOMING(args, object, rx_bytes); \
+               DRAW_BANDWIDTH_OUTGOING(args, object, tx_bytes); \
+       } while (0)
+
+#define DRAW_BANDWIDTH_INCOMING(args, object, rx_bytes) \
+       __DRAW_BANDWIDTH(args, object, rx_bytes, GREEN, _("Incoming Traffic"))
+
+#define DRAW_BANDWIDTH_OUTGOING(args, object, tx_bytes) \
+       __DRAW_BANDWIDTH(args, object, tx_bytes, RED, _("Outgoing Traffic"))
+
+#define __DRAW_BANDWIDTH(args, object, bytes, color, label) \
+       do { \
+               COMPUTE_BITS(args, FIELD_BITS(bytes), object, bytes); \
+               DRAW_AREA_WITH_LABEL(args, FIELD_BITS(bytes), object, color, label); \
+               PRINT_CAMM(args, bytes, object, BPS, _("Bps")); \
+       } while (0)
+
 #endif /* TELEMETRY_GRAPHS_GRAPH_H */
diff --git a/src/daemon/graphs/hostapd-station-bandwidth.c b/src/daemon/graphs/hostapd-station-bandwidth.c
new file mode 100644 (file)
index 0000000..86ec598
--- /dev/null
@@ -0,0 +1,64 @@
+/*#############################################################################
+#                                                                             #
+# telemetryd - The IPFire Telemetry Collection Service                        #
+# 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 "../string.h"
+#include "graph.h"
+#include "hostapd-station-bandwidth.h"
+
+static int hostapd_station_bandwidth_title(td_ctx* ctx, td_graph* graph,
+               const char* object, char* title, size_t length) {
+       return __td_string_format(title, length, _("Station %s - Bandwidth"), object);
+}
+
+static int hostapd_station_bandwidth_vlabel(td_ctx* ctx, td_graph* graph,
+               const char* object, char* vlabel, size_t length) {
+       return __td_string_set(vlabel, length, _("Bits Per Second"));
+}
+
+static int hostapd_station_bandwidth_render(td_ctx* ctx,
+               td_graph* graph, td_args* args, const char* object) {
+       int r;
+
+       // Require the source
+       r = td_graph_require_source(graph, args, "hostapd", object);
+       if (r < 0)
+               return r;
+
+       // Header
+       PRINT_HEADER4(args, _("Current"), _("Average"), _("Minimum"), _("Maximum"));
+
+       // Draw the bandwidth graph
+       DRAW_BANDWIDTH(args, object, "rx_bytes", "tx_bytes");
+
+       return 0;
+}
+
+const td_graph_impl hostapd_station_bandwidth_graph = {
+       .name    = "HostapdStationBandwidth",
+       .render  = hostapd_station_bandwidth_render,
+       .title   = hostapd_station_bandwidth_title,
+       .vlabel  = hostapd_station_bandwidth_vlabel,
+
+       // Limits
+       .lower_limit = 0,
+       .upper_limit = LONG_MAX,
+};
diff --git a/src/daemon/graphs/hostapd-station-bandwidth.h b/src/daemon/graphs/hostapd-station-bandwidth.h
new file mode 100644 (file)
index 0000000..eb5c12a
--- /dev/null
@@ -0,0 +1,28 @@
+/*#############################################################################
+#                                                                             #
+# telemetryd - The IPFire Telemetry Collection Service                        #
+# 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 TELEMETRY_GRAPH_HOSTAPD_STATION_BANDWIDTH_H
+#define TELEMETRY_GRAPH_HOSTAPD_STATION_BANDWIDTH_H
+
+#include "../graph.h"
+
+extern const td_graph_impl hostapd_station_bandwidth_graph;
+
+#endif /* TELEMETRY_GRAPH_HOSTAPD_STATION_BANDWIDTH_H */