]> git.ipfire.org Git - oddments/collecty.git/commitdiff
graphs: Pass the options array to the render function
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 30 Oct 2025 22:40:10 +0000 (22:40 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 30 Oct 2025 22:40:10 +0000 (22:40 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
16 files changed:
src/daemon/graph.c
src/daemon/graph.h
src/daemon/graphs/conntrack.c
src/daemon/graphs/contextswitches.c
src/daemon/graphs/cpufreq.c
src/daemon/graphs/disk.c
src/daemon/graphs/hostapd-station-bandwidth.c
src/daemon/graphs/hostapd-station-rate-info.c
src/daemon/graphs/hostapd-station-signal.c
src/daemon/graphs/legacy-suricata.c
src/daemon/graphs/loadavg.c
src/daemon/graphs/memory.c
src/daemon/graphs/pressure.c
src/daemon/graphs/processor.c
src/daemon/graphs/unbound.c
src/daemon/graphs/uptime.c

index 8d328b3eddb9694ad973258d332cbe9f17bf2cae..267de7044e99a888c9a371e5c271a71c46486a32 100644 (file)
@@ -443,7 +443,7 @@ int td_graph_render(td_graph* self, const char* object,
        }
 
        // Call the implementation to add some arguments
-       r = self->impl->render(self->ctx, self, args, object);
+       r = self->impl->render(self->ctx, self, options, args, object);
        if (r < 0)
                goto ERROR;
 
index 959da3e4f832314f199d6309a0d93377c4aa504d..e244c3e41a71517dadfff5ecafbefffcd95b56f6 100644 (file)
@@ -28,6 +28,31 @@ typedef struct td_graph td_graph;
 #include "daemon.h"
 #include "graph.h"
 
+typedef struct td_graph_render_options {
+       // Output Format
+       const char* format;
+
+       // Locale
+       const char* locale;
+
+       // Dimensions
+       struct {
+               unsigned int h;
+               unsigned int w;
+       } dimensions;
+
+       // Interval
+       struct {
+               time_t t_start;
+               time_t t_end;
+       } interval;
+
+       // Flags
+       enum {
+               TD_GRAPH_OMIT_TITLE = (1 << 0),
+       } flags;
+} td_graph_render_options;
+
 typedef struct td_graph_impl {
        // Name
        const char* name;
@@ -48,7 +73,7 @@ typedef struct td_graph_impl {
        int (*available)(td_ctx* ctx, td_daemon* daemon);
 
        // Render!
-       int (*render)(td_ctx* ctx, td_graph* graph,
+       int (*render)(td_ctx* ctx, td_graph* graph, const td_graph_render_options* options,
                td_args* args, const char* object);
 
        // Title
@@ -74,34 +99,18 @@ int td_graph_require_source(td_graph* self,
 int td_graph_require_sources(td_graph* self,
        td_args* args, const char* name, const char** objects);
 
-typedef struct td_graph_render_options {
-       // Output Format
-       const char* format;
-
-       // Locale
-       const char* locale;
-
-       // Dimensions
-       struct {
-               unsigned int h;
-               unsigned int w;
-       } dimensions;
-
-       // Interval
-       struct {
-               time_t t_start;
-               time_t t_end;
-       } interval;
-
-       // Flags
-       enum {
-               TD_GRAPH_OMIT_TITLE = (1 << 0),
-       } flags;
-} 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);
 
+/*
+       Temperatures
+*/
+typedef enum td_graph_temps {
+       TD_GRAPH_TEMP_KELVIN,
+       TD_GRAPH_TEMP_CELSIUS,
+       TD_GRAPH_TEMP_FAHRENHEIT,
+} td_graph_temps;
+
 /*
        Commonly used vlabels
 */
index ce44afbe9edb7eea3d9a43682352ce98adb333f7..bce49df1735e231e97e29691bbe2bc6a90c8117f 100644 (file)
@@ -34,8 +34,8 @@ static int conntrack_vlabel(td_ctx* ctx,
        return __td_string_set(vlabel, length, _("Entries"));
 }
 
-static int conntrack_render(td_ctx* ctx,
-               td_graph* graph, td_args* args, const char* object) {
+static int conntrack_render(td_ctx* ctx, td_graph* graph,
+               const td_graph_render_options* options, td_args* args, const char* object) {
        int r;
 
        // This requires the conntrack source
index ffc55601d8ee484915e95ce8078a52d4b1bfb454..83e8fbe181fa4f17c60531cb02a0cb182aa01b7c 100644 (file)
@@ -34,8 +34,8 @@ static int contextswitches_vlabel(td_ctx* ctx,
        return __td_string_set(vlabel, length, _("Context Switches/s"));
 }
 
-static int contextswitches_render(td_ctx* ctx,
-               td_graph* graph, td_args* args, const char* object) {
+static int contextswitches_render(td_ctx* ctx, td_graph* graph,
+               const td_graph_render_options* options, td_args* args, const char* object) {
        int r;
 
        // This requires the contextswitches source
index e829512fcfc7973bc1cc85a40ef178cfb7ec15a2..f1738b124d68b37bbdb886350e0514e6d067a96d 100644 (file)
@@ -34,8 +34,8 @@ static int cpufreq_vlabel(td_ctx* ctx,
        return __td_string_set(vlabel, length, _("Hz"));
 }
 
-static int cpufreq_render(td_ctx* ctx,
-               td_graph* graph, td_args* args, const char* _object) {
+static int cpufreq_render(td_ctx* ctx, td_graph* graph,
+               const td_graph_render_options* options, td_args* args, const char* _object) {
        char object[NAME_MAX];
        int r;
 
index 91b10c847a6742954fe9c8a66627b0f1298345d3..1c129d1e00af0a86693dc004e9776409e5ac024e 100644 (file)
@@ -28,8 +28,8 @@ static int disk_temp_title(td_ctx* ctx, td_graph* graph,
        return __td_string_set(title, length, _("Disk Temperature"));
 }
 
-static int disk_temp_render(td_ctx* ctx,
-               td_graph* graph, td_args* args, const char* object) {
+static int disk_temp_render(td_ctx* ctx, td_graph* graph,
+               const td_graph_render_options* options, td_args* args, const char* object) {
        int r;
 
        // Load all sources
index 76f65f70fbd7e9f0173c5dcd2c70bef54c194cc4..dab3362ecb0015f75b8f150e5d8498798c462eaf 100644 (file)
@@ -29,8 +29,8 @@ 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_render(td_ctx* ctx,
-               td_graph* graph, td_args* args, const char* object) {
+static int hostapd_station_bandwidth_render(td_ctx* ctx,td_graph* graph,
+               const td_graph_render_options* options, td_args* args, const char* object) {
        int r;
 
        // Require the source
index 14e63ea8ccf3d3abdfc074cfba670fff7e9db826..83b792c2c8c0b90c17fc7f13940a8e3760574c54 100644 (file)
@@ -29,8 +29,8 @@ 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_render(td_ctx* ctx,
-               td_graph* graph, td_args* args, const char* object) {
+static int hostapd_station_rate_info_render(td_ctx* ctx, td_graph* graph,
+               const td_graph_render_options* options, td_args* args, const char* object) {
        int r;
 
        // Require the source
index 903f489409126239531463b4bc0c149ff2cae971..3c566d09164a6c97da0f152301a0c1b4b4af2926 100644 (file)
@@ -41,8 +41,8 @@ static int hostapd_station_signal_vlabel(td_ctx* ctx, td_graph* graph,
        return __td_string_set(vlabel, length, _("RSSI - dBm"));
 }
 
-static int hostapd_station_signal_render(td_ctx* ctx,
-               td_graph* graph, td_args* args, const char* object) {
+static int hostapd_station_signal_render(td_ctx* ctx, td_graph* graph,
+               const td_graph_render_options* options, td_args* args, const char* object) {
        int r;
 
        // This require the source
index eafeb46682b031985c8f9339e65ec9e8d8393a97..f1e9d75b159cdbdf0e42b731c8f724a11cc1a1a4 100644 (file)
@@ -37,8 +37,8 @@ static int legacy_suricata_vlabel(td_ctx* ctx, td_graph* graph,
        return __td_string_set(vlabel, length, _("bps"));
 }
 
-static int legacy_suricata_render(td_ctx* ctx,
-               td_graph* graph, td_args* args, const char* object) {
+static int legacy_suricata_render(td_ctx* ctx, td_graph* graph,
+               const td_graph_render_options* options, td_args* args, const char* object) {
        int r;
 
        const char* chains[] = {
index 613e25e22ffe32bc1727928623fca1df8f123854..6b89dbf2236c273357c456eb941a4c1a23c76ba8 100644 (file)
@@ -34,8 +34,8 @@ static int loadavg_title(td_ctx* ctx, td_graph* graph,
        return __td_string_set(title, length, _("Load Average"));
 }
 
-static int loadavg_render(td_ctx* ctx,
-               td_graph* graph, td_args* args, const char* object) {
+static int loadavg_render(td_ctx* ctx, td_graph* graph,
+               const td_graph_render_options* options, td_args* args, const char* object) {
        int r;
 
        // This requires the loadavg source
index 00f1d8787f36fbd2d96d492f9f3e0383b721b3d5..85178e2e0aebf93914312975bbae4e7709e8cf13 100644 (file)
@@ -42,8 +42,8 @@ static int memory_vlabel(td_ctx* ctx, td_graph* graph,
        return __td_string_set(vlabel, length, _("Bytes"));
 }
 
-static int memory_render(td_ctx* ctx,
-               td_graph* graph, td_args* args, const char* object) {
+static int memory_render(td_ctx* ctx, td_graph* graph,
+               const td_graph_render_options* options, td_args* args, const char* object) {
        int r;
 
        // This requires the loadavg source
index 019ca97d58c716843dc51a08f10e3065f3b437e2..300e95d90770364d9868f8b3f516d17e75fa5aa9 100644 (file)
@@ -29,8 +29,8 @@
 #define COLOR_LOAD60   COLOR_ORANGE
 #define COLOR_LOAD10   COLOR_YELLOW
 
-static int pressure_render(td_ctx* ctx,
-               td_graph* graph, td_args* args, const char* source) {
+static int pressure_render(td_ctx* ctx, td_graph* graph,
+               const td_graph_render_options* options, td_args* args, const char* source) {
        int r;
 
        // This requires the source
@@ -74,9 +74,9 @@ static int pressure_cpu_title(td_ctx* ctx, td_graph* graph,
                        "%s - %s", _("Pressure Stall Information"), _("Processor"));
 }
 
-static int pressure_cpu_render(td_ctx* ctx,
-               td_graph* graph, td_args* args, const char* object) {
-       return pressure_render(ctx, graph, args, "pressure-cpu");
+static int pressure_cpu_render(td_ctx* ctx, td_graph* graph,
+               const td_graph_render_options* options, td_args* args, const char* object) {
+       return pressure_render(ctx, graph, options, args, "pressure-cpu");
 }
 
 const td_graph_impl pressure_cpu_graph = {
@@ -100,9 +100,9 @@ static int pressure_io_title(td_ctx* ctx, td_graph* graph,
                        "%s - %s", _("Pressure Stall Information"), _("Input/Output"));
 }
 
-static int pressure_io_render(td_ctx* ctx,
-               td_graph* graph, td_args* args, const char* object) {
-       return pressure_render(ctx, graph, args, "pressure-io");
+static int pressure_io_render(td_ctx* ctx, td_graph* graph,
+               const td_graph_render_options* options, td_args* args, const char* object) {
+       return pressure_render(ctx, graph, options, args, "pressure-io");
 }
 
 const td_graph_impl pressure_io_graph = {
@@ -126,9 +126,9 @@ static int pressure_memory_title(td_ctx* ctx, td_graph* graph,
                        "%s - %s", _("Pressure Stall Information"), _("Memory"));
 }
 
-static int pressure_memory_render(td_ctx* ctx,
-               td_graph* graph, td_args* args, const char* object) {
-       return pressure_render(ctx, graph, args, "pressure-memory");
+static int pressure_memory_render(td_ctx* ctx, td_graph* graph,
+               const td_graph_render_options* options, td_args* args, const char* object) {
+       return pressure_render(ctx, graph, options, args, "pressure-memory");
 }
 
 const td_graph_impl pressure_memory_graph = {
index 66142a2d97e887fd2cac5dc8c00d287596b20fa4..fe58c489ed8f54e3b491b3ad672c8400cb5d2005 100644 (file)
@@ -44,8 +44,8 @@ static int processor_vlabel(td_ctx* ctx, td_graph* graph,
        return __td_string_set(vlabel, length, _("Percent"));
 }
 
-static int processor_render(td_ctx* ctx,
-               td_graph* graph, td_args* args, const char* object) {
+static int processor_render(td_ctx* ctx, td_graph* graph,
+               const td_graph_render_options* options, td_args* args, const char* object) {
        int r;
 
        // This requires the loadavg source
index 0ac04795951165a420d7c3448773b61cf03a1096..7608fd7e155cb2ac1a449739cf9a4782c2922cd1 100644 (file)
@@ -28,8 +28,8 @@ static int unbound_queries_title(td_ctx* ctx, td_graph* graph,
        return __td_string_set(title, length, _("DNS Queries"));
 }
 
-static int unbound_queries_render(td_ctx* ctx,
-               td_graph* graph, td_args* args, const char* object) {
+static int unbound_queries_render(td_ctx* ctx, td_graph* graph,
+               const td_graph_render_options* options, td_args* args, const char* object) {
        int r;
 
        // Load all sources
@@ -78,8 +78,8 @@ static int unbound_recursion_time_title(td_ctx* ctx, td_graph* graph,
        return __td_string_set(title, length, _("DNS Recursion Time"));
 }
 
-static int unbound_recursion_time_render(td_ctx* ctx,
-               td_graph* graph, td_args* args, const char* object) {
+static int unbound_recursion_time_render(td_ctx* ctx, td_graph* graph,
+               const td_graph_render_options* options, td_args* args, const char* object) {
        int r;
 
        // Load all sources
index e118c4a84ebed6d6bc294e3bf0722c6cb9a7a217..181dc83f376756ccd9bb7fc2da494a1c5427d678 100644 (file)
@@ -29,8 +29,8 @@ static int uptime_title(td_ctx* ctx, td_graph* graph,
        return __td_string_set(title, length, _("Uptime"));
 }
 
-static int uptime_render(td_ctx* ctx,
-               td_graph* graph, td_args* args, const char* object) {
+static int uptime_render(td_ctx* ctx, td_graph* graph,
+               const td_graph_render_options* options, td_args* args, const char* object) {
        int r;
 
        // This requires the uptime source