From: Michael Tremer Date: Tue, 11 Nov 2025 20:26:42 +0000 (+0000) Subject: graphs: Add a new legacy gateway latency graph X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d4c55575f8daecbc4a71209eda86eb894bc16bf1;p=collecty.git graphs: Add a new legacy gateway latency graph Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 56d03f4..fb37c9b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -126,6 +126,8 @@ dist_telemetryd_SOURCES = \ src/daemon/graphs/hostapd-station-rate-info.h \ src/daemon/graphs/hostapd-station-signal.c \ src/daemon/graphs/hostapd-station-signal.h \ + src/daemon/graphs/legacy-gateway-latency4.c \ + src/daemon/graphs/legacy-gateway-latency4.h \ src/daemon/graphs/legacy-suricata.c \ src/daemon/graphs/legacy-suricata.h \ src/daemon/graphs/loadavg.c \ diff --git a/src/daemon/graphs.c b/src/daemon/graphs.c index 51b7ab6..d7fd551 100644 --- a/src/daemon/graphs.c +++ b/src/daemon/graphs.c @@ -43,6 +43,7 @@ #include "graphs/uptime.h" // Legacy graphs +#include "graphs/legacy-gateway-latency4.h" #include "graphs/legacy-suricata.h" // Register all graphs @@ -72,6 +73,7 @@ static const td_graph_impl* graph_impls[] = { &unbound_recursion_time_graph, // Legacy + &legacy_gateway_latency4_graph, &legacy_suricata_graph, NULL, diff --git a/src/daemon/graphs/graph.h b/src/daemon/graphs/graph.h index 58e043e..c0d3d5a 100644 --- a/src/daemon/graphs/graph.h +++ b/src/daemon/graphs/graph.h @@ -173,6 +173,10 @@ static inline int __DRAW(td_args* args, const char* what, const char* field, DRAW_AREA_OUTLINE_WITH_LABEL(args, field, object, color, flags, label, ##__VA_ARGS__); \ } while(0) +// Draws an invisible AREA +#define DRAW_SPACER(args, field, object) \ + SCRIPT(args, "AREA:" FIELD, FIELD_AND_OBJECT(field, object)) + // Horizontal lines #define DRAW_HRULE(args, value, color) \ SCRIPT(args, "HRULE:%lf" color, (double)value) @@ -229,11 +233,13 @@ static inline int __DRAW(td_args* args, const char* what, const char* field, } while (0) // Handles for fields +#define FIELD_SPACER(field) field "_spacer" #define FIELD_CURRENT(field) field "_cur" #define FIELD_AVERAGE(field) field "_avg" #define FIELD_MINIMUM(field) field "_min" #define FIELD_MAXIMUM(field) field "_max" #define FIELD_PERCENT(field) field "_p" +#define FIELD_STDDEV2(field) field "_stddev2" #define FIELD_INF(field) field "_inf" #define FIELD_NEGINF(field) field "_neginf" #define FIELD_BITS(field) field "_bits" @@ -350,6 +356,17 @@ static inline int __DRAW(td_args* args, const char* what, const char* field, VALUE_ALL(args, FIELD_BYTES(field), object); \ } while (0) +/* + Draw a standard deviation (this takes the baseline and the deviation) +*/ +#define DRAW_STDDEV(args, baseline, stddev, object, color) \ + do { \ + COMPUTE_DIFFERENCE(args, FIELD_SPACER(baseline), object, baseline, object, stddev, object); \ + COMPUTE_MULTIPLY(args, FIELD_STDDEV2(stddev), object, stddev, object, 2); \ + DRAW_SPACER(args, FIELD_SPACER(baseline), object); \ + DRAW_AREA_BACKGROUND(args, FIELD_STDDEV2(stddev), object, color, STACKED); \ + } while (0) + /* This draws an I/O graph */ diff --git a/src/daemon/graphs/legacy-gateway-latency4.c b/src/daemon/graphs/legacy-gateway-latency4.c new file mode 100644 index 0000000..66acab9 --- /dev/null +++ b/src/daemon/graphs/legacy-gateway-latency4.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 "graph.h" +#include "legacy-gateway-latency4.h" + +static int legacy_gateway_latency4_title(td_ctx* ctx, td_graph* graph, + const char* object, char* title, size_t length) { + return __td_string_set(title, length, _("Latency to the Default Gateway")); +} + +static int legacy_gateway_latency4_render(td_ctx* ctx, td_graph* graph, + const td_graph_render_options* options, td_args* args, const char* object) { + int r; + + // Load all sources + r = td_graph_require_source(graph, args, "legacy-gateway-latency4", NULL); + if (r < 0) + return r; + + // Header + PRINT_HEADER4(args, _("Current"), _("Average"), _("Minimum"), _("Maximum")); + + // Draw the stddev area + DRAW_STDDEV(args, "latency", "stddev", NULL, COLOR_DEFAULT); + + // Draw the measured latency + DRAW_LINE_WITH_LABEL(args, 1, "latency", NULL, COLOR_DEFAULT, 0, _("Latency")); + PRINT_CAMM(args, "latency", NULL, SECONDS_HIGHRES); + + PRINT_EMPTY_LINE(args); + + return 0; +} + +const td_graph_impl legacy_gateway_latency4_graph = { + .name = "LegacyGatewayLatency4", + .render = legacy_gateway_latency4_render, + .title = legacy_gateway_latency4_title, + .vlabel = td_graph_vlabel_seconds, + + // Limits + .lower_limit = 0, + .upper_limit = LONG_MAX, +}; diff --git a/src/daemon/graphs/legacy-gateway-latency4.h b/src/daemon/graphs/legacy-gateway-latency4.h new file mode 100644 index 0000000..2ca80af --- /dev/null +++ b/src/daemon/graphs/legacy-gateway-latency4.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_LEGACY_GATEWAY_LATENCY4_H +#define TELEMETRY_GRAPH_LEGACY_GATEWAY_LATENCY4_H + +#include "../graph.h" + +extern const td_graph_impl legacy_gateway_latency4_graph; + +#endif /* TELEMETRY_GRAPH_LEGACY_GATEWAY_LATENCY4_H */