From: Michael Tremer Date: Thu, 30 Oct 2025 18:07:57 +0000 (+0000) Subject: graphs: Create commonly used vlabel functions X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bf24a515b6597c16be6f51ef44b64efc326e43d7;p=telemetry.git graphs: Create commonly used vlabel functions Signed-off-by: Michael Tremer --- diff --git a/src/daemon/graph.c b/src/daemon/graph.c index 2dde9fa..3f1951b 100644 --- a/src/daemon/graph.c +++ b/src/daemon/graph.c @@ -29,6 +29,8 @@ #include "ctx.h" #include "daemon.h" #include "graph.h" +#include "i18n.h" +#include "string.h" #include "time.h" // Maximum length of the title/vlabel @@ -447,3 +449,18 @@ ERROR: return r; } + +int td_graph_vlabel_bps(td_ctx* ctx, td_graph* graph, + const char* object, char* vlabel, size_t length) { + return __td_string_set(vlabel, length, _("Bits Per Second")); +} + +int td_graph_vlabel_days(td_ctx* ctx, td_graph* graph, + const char* object, char* vlabel, size_t length) { + return __td_string_set(vlabel, length, _("Days")); +} + +int td_graph_vlabel_qps(td_ctx* ctx, td_graph* graph, + const char* object, char* vlabel, size_t length) { + return __td_string_set(vlabel, length, _("Queries Per Second")); +} diff --git a/src/daemon/graph.h b/src/daemon/graph.h index 8b58d22..b2d505a 100644 --- a/src/daemon/graph.h +++ b/src/daemon/graph.h @@ -99,4 +99,17 @@ typedef struct td_graph_render_options { int td_graph_render(td_graph* self, const char* object, const td_graph_render_options* options, char** buffer, size_t* length); +/* + Commonly used vlabels +*/ + +int td_graph_vlabel_bps(td_ctx* ctx, td_graph* graph, + const char* object, char* vlabel, size_t length); + +int td_graph_vlabel_days(td_ctx* ctx, td_graph* graph, + const char* object, char* vlabel, size_t length); + +int td_graph_vlabel_qps(td_ctx* ctx, td_graph* graph, + const char* object, char* vlabel, size_t length); + #endif /* TELEMETRY_GRAPH_H */ diff --git a/src/daemon/graphs/hostapd-station-bandwidth.c b/src/daemon/graphs/hostapd-station-bandwidth.c index 86ec598..76f65f7 100644 --- a/src/daemon/graphs/hostapd-station-bandwidth.c +++ b/src/daemon/graphs/hostapd-station-bandwidth.c @@ -29,11 +29,6 @@ static int hostapd_station_bandwidth_title(td_ctx* ctx, td_graph* graph, 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; @@ -56,7 +51,7 @@ 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, + .vlabel = td_graph_vlabel_bps, // Limits .lower_limit = 0, diff --git a/src/daemon/graphs/hostapd-station-rate-info.c b/src/daemon/graphs/hostapd-station-rate-info.c index f1d2c91..14e63ea 100644 --- a/src/daemon/graphs/hostapd-station-rate-info.c +++ b/src/daemon/graphs/hostapd-station-rate-info.c @@ -29,11 +29,6 @@ static int hostapd_station_rate_info_title(td_ctx* ctx, td_graph* graph, return __td_string_format(title, length, _("Station %s - Rate Information"), object); } -static int hostapd_station_rate_info_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_rate_info_render(td_ctx* ctx, td_graph* graph, td_args* args, const char* object) { int r; @@ -61,7 +56,7 @@ const td_graph_impl hostapd_station_rate_info_graph = { .name = "HostapdStationRateInfo", .render = hostapd_station_rate_info_render, .title = hostapd_station_rate_info_title, - .vlabel = hostapd_station_rate_info_vlabel, + .vlabel = td_graph_vlabel_bps, // Limits .lower_limit = 0, diff --git a/src/daemon/graphs/unbound.c b/src/daemon/graphs/unbound.c index 11220df..2e4aa4c 100644 --- a/src/daemon/graphs/unbound.c +++ b/src/daemon/graphs/unbound.c @@ -28,11 +28,6 @@ static int unbound_queries_title(td_ctx* ctx, td_graph* graph, return __td_string_set(title, length, _("DNS Queries")); } -static int unbound_queries_vlabel(td_ctx* ctx, td_graph* graph, - const char* object, char* vlabel, size_t length) { - return __td_string_set(vlabel, length, _("Queries Per Second")); -} - static int unbound_queries_render(td_ctx* ctx, td_graph* graph, td_args* args, const char* object) { int r; @@ -71,7 +66,7 @@ const td_graph_impl unbound_queries_graph = { .name = "UnboundQueries", .render = unbound_queries_render, .title = unbound_queries_title, - .vlabel = unbound_queries_vlabel, + .vlabel = td_graph_vlabel_qps, // Limits .lower_limit = 0, diff --git a/src/daemon/graphs/uptime.c b/src/daemon/graphs/uptime.c index c5ce5fa..e118c4a 100644 --- a/src/daemon/graphs/uptime.c +++ b/src/daemon/graphs/uptime.c @@ -29,11 +29,6 @@ static int uptime_title(td_ctx* ctx, td_graph* graph, return __td_string_set(title, length, _("Uptime")); } -static int uptime_vlabel(td_ctx* ctx, td_graph* graph, - const char* object, char* vlabel, size_t length) { - return __td_string_set(vlabel, length, _("Days")); -} - static int uptime_render(td_ctx* ctx, td_graph* graph, td_args* args, const char* object) { int r; @@ -61,7 +56,7 @@ const td_graph_impl uptime_graph = { .name = "Uptime", .render = uptime_render, .title = uptime_title, - .vlabel = uptime_vlabel, + .vlabel = td_graph_vlabel_days, // Limits .lower_limit = 0,