]> git.ipfire.org Git - collecty.git/commitdiff
graphs: Add temperature unit to the vlabel
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 30 Oct 2025 23:30:48 +0000 (23:30 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 30 Oct 2025 23:30:48 +0000 (23:30 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
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-signal.c
src/daemon/graphs/legacy-suricata.c
src/daemon/graphs/loadavg.c
src/daemon/graphs/memory.c
src/daemon/graphs/processor.c

index 81dcdcd580209668b55647a9fbb277bfeea789b8..5f2ba647ffa12d2c7e721d6dbb4a7d035845dd2a 100644 (file)
@@ -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;
+}
index a3c4bcbc00efb44398f8b6afe9926a67753b5043..99d6bb474463da336c7153c8ad11ffe08433247d 100644 (file)
@@ -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 */
index bce49df1735e231e97e29691bbe2bc6a90c8117f..3ac2521da1a8e7deb9fac4612060955d90c38f13 100644 (file)
@@ -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"));
 }
 
index 83e8fbe181fa4f17c60531cb02a0cb182aa01b7c..7873a5ddcc6dab59f918261e055ad05c5d3374b2 100644 (file)
@@ -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"));
 }
 
index f1738b124d68b37bbdb886350e0514e6d067a96d..8180aa7f23e1acd29adaf61330bd3a2b6120de08 100644 (file)
@@ -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"));
 }
 
index ffec74611477774858ef7523660a91aa606faede..2d36421458f3675664e512b3d8f4bffc9b0d885a 100644 (file)
@@ -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,
index 3c566d09164a6c97da0f152301a0c1b4b4af2926..a607ec098e9bae9724cd8d73f799f1e3583a77d5 100644 (file)
@@ -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"));
 }
 
index f1e9d75b159cdbdf0e42b731c8f724a11cc1a1a4..6f69c50d763e583bf9950cd9fb4a07a11a5c2d69 100644 (file)
@@ -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"));
 }
 
index 6b89dbf2236c273357c456eb941a4c1a23c76ba8..66a9f7e0887f36c1fd00744dc4e9f795ac7623fc 100644 (file)
@@ -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,
index 85178e2e0aebf93914312975bbae4e7709e8cf13..d5cce4f718e0635443804d9d1effcc912dd34fe6 100644 (file)
@@ -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"));
 }
 
index fe58c489ed8f54e3b491b3ad672c8400cb5d2005..eda18b348e45f60898ee90a42989e1e074f5bfb7 100644 (file)
@@ -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"));
 }