]> git.ipfire.org Git - collecty.git/commitdiff
graphs: Create commonly used vlabel functions
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 30 Oct 2025 18:07:57 +0000 (18:07 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 30 Oct 2025 18:07:57 +0000 (18:07 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/graph.c
src/daemon/graph.h
src/daemon/graphs/hostapd-station-bandwidth.c
src/daemon/graphs/hostapd-station-rate-info.c
src/daemon/graphs/unbound.c
src/daemon/graphs/uptime.c

index 2dde9fa7d1d42a83a5300d66482f5270803f46bf..3f1951b48b189755a65a8859977f5f255950e9ce 100644 (file)
@@ -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"));
+}
index 8b58d22a0a61a6328eb3aed9fc09c7a123617158..b2d505ac51e6c8279586354852279342ceee5bec 100644 (file)
@@ -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 */
index 86ec59823582e8be1fe917a9e5ffc6bbf1537e3e..76f65f70fbd7e9f0173c5dcd2c70bef54c194cc4 100644 (file)
@@ -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,
index f1d2c91bf135d458673073959e929442636759de..14e63ea8ccf3d3abdfc074cfba670fff7e9db826 100644 (file)
@@ -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,
index 11220dfd8347f744a64e829182feb12da0c859ef..2e4aa4c3b742c64c253d27456d9701633ae2a106 100644 (file)
@@ -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,
index c5ce5fa5c844bb9e6ca3903dc4ced0483b44ef89..e118c4a84ebed6d6bc294e3bf0722c6cb9a7a217 100644 (file)
@@ -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,