From: Michael Tremer Date: Fri, 27 Mar 2026 18:04:22 +0000 (+0000) Subject: graphs: Add a Processor Power Consumption graph X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4c14701554b89935cfd5457c4dd536263a5caa93;p=telemetry.git graphs: Add a Processor Power Consumption graph Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 5862776..b0d9157 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/po/POTFILES.in b/po/POTFILES.in index 6bc8aae..2c0dcd7 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -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 diff --git a/po/telemetry.pot b/po/telemetry.pot index 5df2ad9..cba8f07 100644 --- a/po/telemetry.pot +++ b/po/telemetry.pot @@ -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 \n" "Language-Team: LANGUAGE \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 "" diff --git a/src/daemon/colors.h b/src/daemon/colors.h index 5b0279b..cd21ed1 100644 --- a/src/daemon/colors.h +++ b/src/daemon/colors.h @@ -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 diff --git a/src/daemon/graph.c b/src/daemon/graph.c index 6f98324..66e5d6c 100644 --- a/src/daemon/graph.c +++ b/src/daemon/graph.c @@ -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")); +} diff --git a/src/daemon/graph.h b/src/daemon/graph.h index 606b752..5421f71 100644 --- a/src/daemon/graph.h +++ b/src/daemon/graph.h @@ -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 */ diff --git a/src/daemon/graphs.c b/src/daemon/graphs.c index 7f35a27..a498b64 100644 --- a/src/daemon/graphs.c +++ b/src/daemon/graphs.c @@ -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, diff --git a/src/daemon/graphs/graph.h b/src/daemon/graphs/graph.h index 695a8ff..c91f8a6 100644 --- a/src/daemon/graphs/graph.h +++ b/src/daemon/graphs/graph.h @@ -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 index 0000000..77c1951 --- /dev/null +++ b/src/daemon/graphs/processor-power-consumption.c @@ -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 . # +# # +#############################################################################*/ + +#include + +#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 index 0000000..2c527fb --- /dev/null +++ b/src/daemon/graphs/processor-power-consumption.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_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 */