From: Michael Tremer Date: Thu, 30 Oct 2025 23:30:48 +0000 (+0000) Subject: graphs: Add temperature unit to the vlabel X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3bb0165329f6200b34fc76d6d981e02a2eae37d1;p=telemetry.git graphs: Add temperature unit to the vlabel Signed-off-by: Michael Tremer --- diff --git a/src/daemon/graph.c b/src/daemon/graph.c index 81dcdcd..5f2ba64 100644 --- a/src/daemon/graph.c +++ b/src/daemon/graph.c @@ -405,7 +405,7 @@ int td_graph_render(td_graph* self, const char* object, // Set the vertical label if (self->impl->vlabel) { // Fetch the vertical label - r = self->impl->vlabel(self->ctx, self, object, vlabel, sizeof(vlabel)); + r = self->impl->vlabel(self->ctx, self, options, object, vlabel, sizeof(vlabel)); if (r < 0) { ERROR(self->ctx, "Failed to render the vertical label: %s\n", strerror(-r)); goto ERROR; @@ -546,21 +546,37 @@ td_graph_temps td_graph_temperature(const td_graph_render_options* options) { } int td_graph_vlabel_bps(td_ctx* ctx, td_graph* graph, - const char* object, char* vlabel, size_t length) { + const td_graph_render_options* options, 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) { + const td_graph_render_options* options, 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) { + const td_graph_render_options* options, const char* object, char* vlabel, size_t length) { return __td_string_set(vlabel, length, _("Queries Per Second")); } int td_graph_vlabel_seconds(td_ctx* ctx, td_graph* graph, - const char* object, char* vlabel, size_t length) { + const td_graph_render_options* options, const char* object, char* vlabel, size_t length) { return __td_string_set(vlabel, length, _("Seconds")); } + +int td_graph_vlabel_temp(td_ctx* ctx, td_graph* graph, + const td_graph_render_options* options, const char* object, char* vlabel, size_t length) { + switch (td_graph_temperature(options)) { + case TD_GRAPH_TEMP_KELVIN: + return __td_string_set(vlabel, length, _("Kelvin")); + + case TD_GRAPH_TEMP_CELSIUS: + return __td_string_set(vlabel, length, _("° Celsius")); + + case TD_GRAPH_TEMP_FAHRENHEIT: + return __td_string_set(vlabel, length, _("° Fahrenheit")); + } + + return -EINVAL; +} diff --git a/src/daemon/graph.h b/src/daemon/graph.h index a3c4bcb..99d6bb4 100644 --- a/src/daemon/graph.h +++ b/src/daemon/graph.h @@ -81,7 +81,7 @@ typedef struct td_graph_impl { const char* object, char* title, size_t length); // Vertical Label - int (*vlabel)(td_ctx* ctx, td_graph* graph, + int (*vlabel)(td_ctx* ctx, td_graph* graph, const td_graph_render_options* options, const char* object, char* vlabel, size_t length); } td_graph_impl; @@ -118,15 +118,18 @@ td_graph_temps td_graph_temperature(const td_graph_render_options* options); */ int td_graph_vlabel_bps(td_ctx* ctx, td_graph* graph, - const char* object, char* vlabel, size_t length); + const td_graph_render_options* options, 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); + const td_graph_render_options* options, 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); + const td_graph_render_options* options, const char* object, char* vlabel, size_t length); int td_graph_vlabel_seconds(td_ctx* ctx, td_graph* graph, - const char* object, char* vlabel, size_t length); + const td_graph_render_options* options, const char* object, char* vlabel, size_t length); + +int td_graph_vlabel_temp(td_ctx* ctx, td_graph* graph, + const td_graph_render_options* options, const char* object, char* vlabel, size_t length); #endif /* TELEMETRY_GRAPH_H */ diff --git a/src/daemon/graphs/conntrack.c b/src/daemon/graphs/conntrack.c index bce49df..3ac2521 100644 --- a/src/daemon/graphs/conntrack.c +++ b/src/daemon/graphs/conntrack.c @@ -29,8 +29,8 @@ static int conntrack_title(td_ctx* ctx, return __td_string_set(title, length, _("Connection Tracking Table")); } -static int conntrack_vlabel(td_ctx* ctx, - td_graph* graph, const char* object, char* vlabel, size_t length) { +static int conntrack_vlabel(td_ctx* ctx, td_graph* graph, + const td_graph_render_options* options, const char* object, char* vlabel, size_t length) { return __td_string_set(vlabel, length, _("Entries")); } diff --git a/src/daemon/graphs/contextswitches.c b/src/daemon/graphs/contextswitches.c index 83e8fbe..7873a5d 100644 --- a/src/daemon/graphs/contextswitches.c +++ b/src/daemon/graphs/contextswitches.c @@ -29,8 +29,8 @@ static int contextswitches_title(td_ctx* ctx, return __td_string_set(title, length, _("Context Switches")); } -static int contextswitches_vlabel(td_ctx* ctx, - td_graph* graph, const char* object, char* vlabel, size_t length) { +static int contextswitches_vlabel(td_ctx* ctx, td_graph* graph, + const td_graph_render_options* options, const char* object, char* vlabel, size_t length) { return __td_string_set(vlabel, length, _("Context Switches/s")); } diff --git a/src/daemon/graphs/cpufreq.c b/src/daemon/graphs/cpufreq.c index f1738b1..8180aa7 100644 --- a/src/daemon/graphs/cpufreq.c +++ b/src/daemon/graphs/cpufreq.c @@ -29,8 +29,8 @@ static int cpufreq_title(td_ctx* ctx, return __td_string_set(title, length, _("CPU Frequency")); } -static int cpufreq_vlabel(td_ctx* ctx, - td_graph* graph, const char* object, char* vlabel, size_t length) { +static int cpufreq_vlabel(td_ctx* ctx, td_graph* graph, + const td_graph_render_options* options, const char* object, char* vlabel, size_t length) { return __td_string_set(vlabel, length, _("Hz")); } diff --git a/src/daemon/graphs/disk.c b/src/daemon/graphs/disk.c index ffec746..2d36421 100644 --- a/src/daemon/graphs/disk.c +++ b/src/daemon/graphs/disk.c @@ -50,7 +50,7 @@ const td_graph_impl disk_temp_graph = { .name = "DiskTemperature", .render = disk_temp_render, .title = disk_temp_title, - //.vlabel = td_graph_vlabel_qps, + .vlabel = td_graph_vlabel_temp, // Limits .lower_limit = -LONG_MAX, diff --git a/src/daemon/graphs/hostapd-station-signal.c b/src/daemon/graphs/hostapd-station-signal.c index 3c566d0..a607ec0 100644 --- a/src/daemon/graphs/hostapd-station-signal.c +++ b/src/daemon/graphs/hostapd-station-signal.c @@ -37,7 +37,7 @@ static int hostapd_station_signal_title(td_ctx* ctx, td_graph* graph, } static int hostapd_station_signal_vlabel(td_ctx* ctx, td_graph* graph, - const char* object, char* vlabel, size_t length) { + const td_graph_render_options* options, const char* object, char* vlabel, size_t length) { return __td_string_set(vlabel, length, _("RSSI - dBm")); } diff --git a/src/daemon/graphs/legacy-suricata.c b/src/daemon/graphs/legacy-suricata.c index f1e9d75..6f69c50 100644 --- a/src/daemon/graphs/legacy-suricata.c +++ b/src/daemon/graphs/legacy-suricata.c @@ -33,7 +33,7 @@ static int legacy_suricata_title(td_ctx* ctx, td_graph* graph, } static int legacy_suricata_vlabel(td_ctx* ctx, td_graph* graph, - const char* object, char* vlabel, size_t length) { + const td_graph_render_options* options, const char* object, char* vlabel, size_t length) { return __td_string_set(vlabel, length, _("bps")); } diff --git a/src/daemon/graphs/loadavg.c b/src/daemon/graphs/loadavg.c index 6b89dbf..66a9f7e 100644 --- a/src/daemon/graphs/loadavg.c +++ b/src/daemon/graphs/loadavg.c @@ -34,6 +34,11 @@ static int loadavg_title(td_ctx* ctx, td_graph* graph, return __td_string_set(title, length, _("Load Average")); } +static int loadavg_vlabel(td_ctx* ctx, td_graph* graph, + const td_graph_render_options* options, const char* object, char* title, size_t length) { + return __td_string_set(title, length, _("Load Average")); +} + static int loadavg_render(td_ctx* ctx, td_graph* graph, const td_graph_render_options* options, td_args* args, const char* object) { int r; @@ -75,7 +80,7 @@ const td_graph_impl loadavg_graph = { .name = "LoadAverage", .render = loadavg_render, .title = loadavg_title, - .vlabel = loadavg_title, + .vlabel = loadavg_vlabel, // Flags .flags = TELEMETRY_GRAPH_REVERSE, diff --git a/src/daemon/graphs/memory.c b/src/daemon/graphs/memory.c index 85178e2..d5cce4f 100644 --- a/src/daemon/graphs/memory.c +++ b/src/daemon/graphs/memory.c @@ -38,7 +38,7 @@ static int memory_title(td_ctx* ctx, td_graph* graph, } static int memory_vlabel(td_ctx* ctx, td_graph* graph, - const char* object, char* vlabel, size_t length) { + const td_graph_render_options* options, const char* object, char* vlabel, size_t length) { return __td_string_set(vlabel, length, _("Bytes")); } diff --git a/src/daemon/graphs/processor.c b/src/daemon/graphs/processor.c index fe58c48..eda18b3 100644 --- a/src/daemon/graphs/processor.c +++ b/src/daemon/graphs/processor.c @@ -40,7 +40,7 @@ static int processor_title(td_ctx* ctx, td_graph* graph, } static int processor_vlabel(td_ctx* ctx, td_graph* graph, - const char* object, char* vlabel, size_t length) { + const td_graph_render_options* options, const char* object, char* vlabel, size_t length) { return __td_string_set(vlabel, length, _("Percent")); }