]> git.ipfire.org Git - telemetry.git/commitdiff
graphs: Add a Processor Power Consumption graph
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Mar 2026 18:04:22 +0000 (18:04 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Mar 2026 18:04:22 +0000 (18:04 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
po/POTFILES.in
po/telemetry.pot
src/daemon/colors.h
src/daemon/graph.c
src/daemon/graph.h
src/daemon/graphs.c
src/daemon/graphs/graph.h
src/daemon/graphs/processor-power-consumption.c [new file with mode: 0644]
src/daemon/graphs/processor-power-consumption.h [new file with mode: 0644]

index 58627760fbcd829072837c207810cd07b33b8961..b0d91578e15752b2fb1336f428643f213cfddee2 100644 (file)
@@ -146,6 +146,8 @@ dist_telemetryd_SOURCES = \
        src/daemon/graphs/pressure.h \
        src/daemon/graphs/processor.c \
        src/daemon/graphs/processor.h \
+       src/daemon/graphs/processor-power-consumption.c \
+       src/daemon/graphs/processor-power-consumption.h \
        src/daemon/graphs/processor-temperature.c \
        src/daemon/graphs/processor-temperature.h \
        src/daemon/graphs/system-temperature.c \
index 6bc8aae7147a9cbd04d649ecbff099228220b2fa..2c0dcd73dfa6be3171e38504737cd3dbea4176e0 100644 (file)
@@ -55,6 +55,8 @@ src/daemon/graphs/pressure.c
 src/daemon/graphs/pressure.h
 src/daemon/graphs/processor.c
 src/daemon/graphs/processor.h
+src/daemon/graphs/processor-power-consumption.c
+src/daemon/graphs/processor-power-consumption.h
 src/daemon/graphs/processor-temperature.c
 src/daemon/graphs/processor-temperature.h
 src/daemon/graphs/system-temperature.c
index 5df2ad9057d97d5d12f68aa54b17051a85b7514a..cba8f077f80a599f8721d3b3f4c3a7b1ddf0cf80 100644 (file)
@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2026-03-27 17:21+0000\n"
+"POT-Creation-Date: 2026-03-27 18:04+0000\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -50,6 +50,9 @@ msgstr ""
 msgid "° Fahrenheit"
 msgstr ""
 
+msgid "Watts"
+msgstr ""
+
 msgid "Connection Tracking Table"
 msgstr ""
 
@@ -318,6 +321,12 @@ msgstr ""
 msgid "User"
 msgstr ""
 
+msgid "Processor Power Consumption"
+msgstr ""
+
+msgid "Power Consumption"
+msgstr ""
+
 msgid "Processor Temperature"
 msgstr ""
 
index 5b0279bbc6ee90a0764d5efa077bbe3f16b701c2..cd21ed1d19321321ed85379c66015a82084c962c 100644 (file)
@@ -71,6 +71,7 @@
 #define COLOR_MINIMUM                  COLOR_FRESH_LIME
 #define COLOR_MAXIMUM                  COLOR_SOFT_RED
 #define COLOR_LIMIT                            COLOR_CLEAN_AMBER
+#define COLOR_CRITICAL                 COLOR_MAXIMUM
 
 // Signal
 #define COLOR_SIGNAL_STRONG            COLOR_CLEAN_GREEN
index 6f98324e7e06addad1301e221978615540c2b3d9..66e5d6c7b7e4d62f43e3fc27c198988e17fc42db 100644 (file)
@@ -618,3 +618,8 @@ int td_graph_vlabel_temp(td_ctx* ctx, td_graph* graph,
 
        return -EINVAL;
 }
+
+int td_graph_vlabel_watts(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, _("Watts"));
+}
index 606b752f125b384d851128ec467676b720e449bc..5421f71ac075fc44ee12851e45a410c71eda9246 100644 (file)
@@ -160,4 +160,7 @@ int td_graph_vlabel_seconds(td_ctx* ctx, td_graph* graph,
 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);
 
+int td_graph_vlabel_watts(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 7f35a273c90265dddb1c797bb3844d31045dea0b..a498b6403af448e2918f03e2bb9e4b7959803d7b 100644 (file)
@@ -41,6 +41,7 @@
 #include "graphs/memory.h"
 #include "graphs/pressure.h"
 #include "graphs/processor.h"
+#include "graphs/processor-power-consumption.h"
 #include "graphs/processor-temperature.h"
 #include "graphs/system-temperature.h"
 #include "graphs/unbound-cache-performance.h"
@@ -88,6 +89,9 @@ static const td_graph_impl* graph_impls[] = {
        &processor_temperature_graph,
        &system_temperature_graph,
 
+       // Power Consumption
+       &processor_power_consumption_graph,
+
        // Unbound
        &unbound_cache_performance_graph,
        &unbound_cache_usage_graph,
index 695a8ffbe6e501136d4a3713574895979abed34d..c91f8a63c1e5856a1813f321aae5e025e40e703f 100644 (file)
@@ -82,6 +82,9 @@ typedef enum flags {
 #define CELSIUS                        "%%11.2lf °C"
 #define FAHRENHEIT             "%%11.2lf °F"
 
+// Power
+#define WATTS                  "%%14.2lf W"
+
 // Macro to terminate a line
 #define EOL                            "\\j"
 
diff --git a/src/daemon/graphs/processor-power-consumption.c b/src/daemon/graphs/processor-power-consumption.c
new file mode 100644 (file)
index 0000000..77c1951
--- /dev/null
@@ -0,0 +1,104 @@
+/*#############################################################################
+#                                                                             #
+# 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 "processor-power-consumption.h"
+
+static const char* supported_sensors[] = {
+       // AMD
+       "fam15h_power-*",
+       NULL,
+};
+
+static int processor_power_consumption_title(td_ctx* ctx, td_graph* graph,
+               const char* object, char* title, size_t length) {
+       return __td_string_set(title, length, _("Processor Power Consumption"));
+}
+
+static int processor_power_consumption_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-power", name);
+       if (r < 0)
+               return r;
+
+       // Header
+       PRINT_HEADER4(state->args, _("Current"), _("Average"), _("Minimum"), _("Maximum"));
+
+       // Draw the power consumption
+       DRAW_AREA_WITH_LABEL(state->args, "average", name,
+                       COLOR_DEFAULT, 0, _("Power Consumption"));
+       PRINT_CAMM(state->args, "average", name, WATTS);
+
+       // Draw the maximum consumption
+       DRAW_LINE_WITH_LABEL(state->args, 1, "crit", name,
+                       COLOR_CRITICAL, DASHED|SKIPSCALE, _("Maximum"));
+       PRINT_CURRENT(state->args, "crit", name, WATTS);
+       PRINT_NOTHING(state->args);
+       PRINT_NOTHING(state->args);
+       PRINT_NOTHING(state->args);
+       PRINT_EOL(state->args);
+
+       return 0;
+}
+
+static int processor_power_consumption_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 power sensors
+       return td_sensors_walk(ctx, NULL, SENSORS_FEATURE_POWER,
+               processor_power_consumption_render_sensor, &state);
+}
+
+const td_graph_impl processor_power_consumption_graph = {
+       .name    = "ProcessorPowerConsumption",
+       .render  = processor_power_consumption_render,
+       .title   = processor_power_consumption_title,
+       .vlabel  = td_graph_vlabel_watts,
+
+       // Limits
+       .lower_limit = 0,
+       .upper_limit = LONG_MAX,
+};
diff --git a/src/daemon/graphs/processor-power-consumption.h b/src/daemon/graphs/processor-power-consumption.h
new file mode 100644 (file)
index 0000000..2c527fb
--- /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_PROCESSOR_POWER_CONSUMPTION_H
+#define TELEMETRY_GRAPH_PROCESSOR_POWER_CONSUMPTION_H
+
+#include "../graph.h"
+
+extern const td_graph_impl processor_power_consumption_graph;
+
+#endif /* TELEMETRY_GRAPH_PROCESSOR_POWER_CONSUMPTION_H */