From: Michael Tremer Date: Fri, 27 Mar 2026 17:23:35 +0000 (+0000) Subject: graphs: Add a system temperature graph X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7f68ab46d0a063ae030fe6f558a325a2838e37db;p=telemetry.git graphs: Add a system temperature graph Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 0629b9a..5862776 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/src/daemon/graphs.c b/src/daemon/graphs.c index 4bfff56..7f35a27 100644 --- a/src/daemon/graphs.c +++ b/src/daemon/graphs.c @@ -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 index 0000000..613e86d --- /dev/null +++ b/src/daemon/graphs/system-temperature.c @@ -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 . # +# # +#############################################################################*/ + +#include + +#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 index 0000000..ab728f2 --- /dev/null +++ b/src/daemon/graphs/system-temperature.h @@ -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 . # +# # +#############################################################################*/ + +#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 */