From: Michael Tremer Date: Tue, 21 Oct 2025 13:37:44 +0000 (+0000) Subject: graphs: Add bandwidth graphs for hostapd stations X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=76364547aed84f705aa804f58245016c0cb40d60;p=telemetry.git graphs: Add bandwidth graphs for hostapd stations Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 88fe9c0..005ffd6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/src/daemon/graphs.c b/src/daemon/graphs.c index 29bcc52..a101c91 100644 --- a/src/daemon/graphs.c +++ b/src/daemon/graphs.c @@ -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, diff --git a/src/daemon/graphs/graph.h b/src/daemon/graphs/graph.h index cc2ab8f..b175314 100644 --- a/src/daemon/graphs/graph.h +++ b/src/daemon/graphs/graph.h @@ -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" @@ -186,6 +187,7 @@ #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)) @@ -226,6 +228,19 @@ 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) ",/", \ @@ -255,4 +270,26 @@ ); \ } 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 index 0000000..86ec598 --- /dev/null +++ b/src/daemon/graphs/hostapd-station-bandwidth.c @@ -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 . # +# # +#############################################################################*/ + +#include + +#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 index 0000000..eb5c12a --- /dev/null +++ b/src/daemon/graphs/hostapd-station-bandwidth.h @@ -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 . # +# # +#############################################################################*/ + +#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 */