]> git.ipfire.org Git - telemetry.git/commitdiff
graphs: Add a system temperature graph
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Mar 2026 17:23:35 +0000 (17:23 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Mar 2026 17:23:35 +0000 (17:23 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/daemon/graphs.c
src/daemon/graphs/system-temperature.c [new file with mode: 0644]
src/daemon/graphs/system-temperature.h [new file with mode: 0644]

index 0629b9a85af5ed3dc8e93f62bc3a54b113af5ec8..58627760fbcd829072837c207810cd07b33b8961 100644 (file)
@@ -148,6 +148,8 @@ dist_telemetryd_SOURCES = \
        src/daemon/graphs/processor.h \
        src/daemon/graphs/processor-temperature.c \
        src/daemon/graphs/processor-temperature.h \
+       src/daemon/graphs/system-temperature.c \
+       src/daemon/graphs/system-temperature.h \
        src/daemon/graphs/unbound-cache-performance.c \
        src/daemon/graphs/unbound-cache-performance.h \
        src/daemon/graphs/unbound-cache-usage.c \
index 4bfff560c052cbf464a1332af8af7ddd4a0526a1..7f35a273c90265dddb1c797bb3844d31045dea0b 100644 (file)
@@ -42,6 +42,7 @@
 #include "graphs/pressure.h"
 #include "graphs/processor.h"
 #include "graphs/processor-temperature.h"
+#include "graphs/system-temperature.h"
 #include "graphs/unbound-cache-performance.h"
 #include "graphs/unbound-cache-usage.h"
 #include "graphs/unbound-memory-usage.h"
@@ -69,7 +70,6 @@ static const td_graph_impl* graph_impls[] = {
 
        // Processor
        &processor_graph,
-       &processor_temperature_graph,
 
        // Disk
        &disk_io_graph,
@@ -84,6 +84,10 @@ static const td_graph_impl* graph_impls[] = {
        &pressure_io_graph,
        &pressure_memory_graph,
 
+       // Temperature
+       &processor_temperature_graph,
+       &system_temperature_graph,
+
        // Unbound
        &unbound_cache_performance_graph,
        &unbound_cache_usage_graph,
diff --git a/src/daemon/graphs/system-temperature.c b/src/daemon/graphs/system-temperature.c
new file mode 100644 (file)
index 0000000..613e86d
--- /dev/null
@@ -0,0 +1,97 @@
+/*#############################################################################
+#                                                                             #
+# telemetryd - The IPFire Telemetry Collection Service                        #
+# Copyright (C) 2026 IPFire Development Team                                  #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#include <limits.h>
+
+#include "../ctx.h"
+#include "../sensors.h"
+#include "../source.h"
+#include "../string.h"
+#include "graph.h"
+#include "system-temperature.h"
+
+static const char* supported_sensors[] = {
+       // ACPI
+       "acpitz-*",
+       NULL,
+};
+
+static int system_temperature_title(td_ctx* ctx, td_graph* graph,
+               const char* object, char* title, size_t length) {
+       return __td_string_set(title, length, _("System Temperature"));
+}
+
+static int system_temperature_render_sensor(td_ctx* ctx, td_source* source,
+               const sensors_feature_type type, const sensors_chip_name* chip,
+               const sensors_feature* feature, void* data) {
+       const td_graph_render_state* state = data;
+       char name[NAME_MAX];
+       int r;
+
+       // Fetch the sensor name
+       r = td_sensors_name(name, chip, feature);
+       if (r < 0)
+               return 0;
+
+       // Skip if this is not a supported sensor
+       if (!td_string_matches_any(name, supported_sensors))
+               return 0;
+
+       // Add the source
+       r = td_graph_require_source(state->graph, state->args, "sensors-temp", name);
+       if (r < 0)
+               return r;
+
+       // Header
+       PRINT_HEADER4(state->args, _("Current"), _("Average"), _("Minimum"), _("Maximum"));
+
+       // Draw the temperature
+       DRAW_TEMPERATURE(state->args, state->options, "current", name, "%s", _("Temperature"));
+
+       // Draw the temperature limits
+       DRAW_TEMPERATURE_MAXIMUM(state->args, state->options, "max", name);
+       DRAW_TEMPERATURE_CRITICAL(state->args, state->options, "crit", name);
+
+       return 0;
+}
+
+static int system_temperature_render(td_ctx* ctx, td_graph* graph,
+               const td_graph_render_options* options, td_args* args, const char* object) {
+       td_graph_render_state state = {
+               .graph   = graph,
+               .options = options,
+               .args    = args,
+       };
+
+       // Walk through all temperature sensors
+       return td_sensors_walk(ctx, NULL, SENSORS_FEATURE_TEMP,
+               system_temperature_render_sensor, &state);
+}
+
+const td_graph_impl system_temperature_graph = {
+       .name    = "SystemTemperature",
+       .render  = system_temperature_render,
+       .title   = system_temperature_title,
+       .vlabel  = td_graph_vlabel_temp,
+
+       // Limits
+       .lower_limit = -LONG_MAX,
+       .upper_limit = LONG_MAX,
+};
diff --git a/src/daemon/graphs/system-temperature.h b/src/daemon/graphs/system-temperature.h
new file mode 100644 (file)
index 0000000..ab728f2
--- /dev/null
@@ -0,0 +1,28 @@
+/*#############################################################################
+#                                                                             #
+# telemetryd - The IPFire Telemetry Collection Service                        #
+# Copyright (C) 2026 IPFire Development Team                                  #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#ifndef TELEMETRY_GRAPH_SYSTEM_TEMPERATURE_H
+#define TELEMETRY_GRAPH_SYSTEM_TEMPERATURE_H
+
+#include "../graph.h"
+
+extern const td_graph_impl system_temperature_graph;
+
+#endif /* TELEMETRY_GRAPH_SYSTEM_TEMPERATURE_H */