From: Michael Tremer Date: Thu, 30 Oct 2025 22:40:10 +0000 (+0000) Subject: graphs: Pass the options array to the render function X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7c7a022c3f84959590315fd31ce30ceaad4011ad;p=telemetry.git graphs: Pass the options array to the render function Signed-off-by: Michael Tremer --- diff --git a/src/daemon/graph.c b/src/daemon/graph.c index 8d328b3..267de70 100644 --- a/src/daemon/graph.c +++ b/src/daemon/graph.c @@ -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; diff --git a/src/daemon/graph.h b/src/daemon/graph.h index 959da3e..e244c3e 100644 --- a/src/daemon/graph.h +++ b/src/daemon/graph.h @@ -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 */ diff --git a/src/daemon/graphs/conntrack.c b/src/daemon/graphs/conntrack.c index ce44afb..bce49df 100644 --- a/src/daemon/graphs/conntrack.c +++ b/src/daemon/graphs/conntrack.c @@ -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 diff --git a/src/daemon/graphs/contextswitches.c b/src/daemon/graphs/contextswitches.c index ffc5560..83e8fbe 100644 --- a/src/daemon/graphs/contextswitches.c +++ b/src/daemon/graphs/contextswitches.c @@ -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 diff --git a/src/daemon/graphs/cpufreq.c b/src/daemon/graphs/cpufreq.c index e829512..f1738b1 100644 --- a/src/daemon/graphs/cpufreq.c +++ b/src/daemon/graphs/cpufreq.c @@ -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; diff --git a/src/daemon/graphs/disk.c b/src/daemon/graphs/disk.c index 91b10c8..1c129d1 100644 --- a/src/daemon/graphs/disk.c +++ b/src/daemon/graphs/disk.c @@ -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 diff --git a/src/daemon/graphs/hostapd-station-bandwidth.c b/src/daemon/graphs/hostapd-station-bandwidth.c index 76f65f7..dab3362 100644 --- a/src/daemon/graphs/hostapd-station-bandwidth.c +++ b/src/daemon/graphs/hostapd-station-bandwidth.c @@ -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 diff --git a/src/daemon/graphs/hostapd-station-rate-info.c b/src/daemon/graphs/hostapd-station-rate-info.c index 14e63ea..83b792c 100644 --- a/src/daemon/graphs/hostapd-station-rate-info.c +++ b/src/daemon/graphs/hostapd-station-rate-info.c @@ -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 diff --git a/src/daemon/graphs/hostapd-station-signal.c b/src/daemon/graphs/hostapd-station-signal.c index 903f489..3c566d0 100644 --- a/src/daemon/graphs/hostapd-station-signal.c +++ b/src/daemon/graphs/hostapd-station-signal.c @@ -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 diff --git a/src/daemon/graphs/legacy-suricata.c b/src/daemon/graphs/legacy-suricata.c index eafeb46..f1e9d75 100644 --- a/src/daemon/graphs/legacy-suricata.c +++ b/src/daemon/graphs/legacy-suricata.c @@ -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[] = { diff --git a/src/daemon/graphs/loadavg.c b/src/daemon/graphs/loadavg.c index 613e25e..6b89dbf 100644 --- a/src/daemon/graphs/loadavg.c +++ b/src/daemon/graphs/loadavg.c @@ -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 diff --git a/src/daemon/graphs/memory.c b/src/daemon/graphs/memory.c index 00f1d87..85178e2 100644 --- a/src/daemon/graphs/memory.c +++ b/src/daemon/graphs/memory.c @@ -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 diff --git a/src/daemon/graphs/pressure.c b/src/daemon/graphs/pressure.c index 019ca97..300e95d 100644 --- a/src/daemon/graphs/pressure.c +++ b/src/daemon/graphs/pressure.c @@ -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 = { diff --git a/src/daemon/graphs/processor.c b/src/daemon/graphs/processor.c index 66142a2..fe58c48 100644 --- a/src/daemon/graphs/processor.c +++ b/src/daemon/graphs/processor.c @@ -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 diff --git a/src/daemon/graphs/unbound.c b/src/daemon/graphs/unbound.c index 0ac0479..7608fd7 100644 --- a/src/daemon/graphs/unbound.c +++ b/src/daemon/graphs/unbound.c @@ -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 diff --git a/src/daemon/graphs/uptime.c b/src/daemon/graphs/uptime.c index e118c4a..181dc83 100644 --- a/src/daemon/graphs/uptime.c +++ b/src/daemon/graphs/uptime.c @@ -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