From: Michael Tremer Date: Thu, 23 Oct 2025 17:47:45 +0000 (+0000) Subject: sources: sensors: Collect power metrics X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=369d45ff4c48b65c4a8692ac2d532ea8f86bd508;p=telemetry.git sources: sensors: Collect power metrics Signed-off-by: Michael Tremer --- diff --git a/src/daemon/sources.c b/src/daemon/sources.c index a3352b4..bca20af 100644 --- a/src/daemon/sources.c +++ b/src/daemon/sources.c @@ -92,6 +92,7 @@ static const td_source_impl* source_impls[] = { &sensors_input_source, &sensors_fan_source, &sensors_temp_source, + &sensors_power_source, #endif /* HAVE_SENSORS */ #if ENABLE_TESTS diff --git a/src/daemon/sources/sensors.c b/src/daemon/sources/sensors.c index b5abe1d..7e09342 100644 --- a/src/daemon/sources/sensors.c +++ b/src/daemon/sources/sensors.c @@ -386,3 +386,64 @@ const td_source_impl sensors_temp_source = { // Methods .heartbeat = sensors_temp_heartbeat, }; + +/* + Power +*/ +static int sensors_power_heartbeat(td_ctx* ctx, td_source* source) { + sensors_value values[] = { + { "average", SENSORS_SUBFEATURE_POWER_AVERAGE }, + { "average_highest", SENSORS_SUBFEATURE_POWER_AVERAGE_HIGHEST }, + { "average_lowest", SENSORS_SUBFEATURE_POWER_AVERAGE_LOWEST }, + { "average_interval", SENSORS_SUBFEATURE_POWER_AVERAGE_INTERVAL }, + { "input", SENSORS_SUBFEATURE_POWER_INPUT }, + { "input_highest", SENSORS_SUBFEATURE_POWER_INPUT_HIGHEST, }, + { "input_lowest", SENSORS_SUBFEATURE_POWER_INPUT_LOWEST }, + { "cap", SENSORS_SUBFEATURE_POWER_CAP }, + { "cap_hyst", SENSORS_SUBFEATURE_POWER_CAP_HYST }, + { "max", SENSORS_SUBFEATURE_POWER_MAX }, + { "min", SENSORS_SUBFEATURE_POWER_MIN }, + { "crit", SENSORS_SUBFEATURE_POWER_CRIT }, + { "lcrit", SENSORS_SUBFEATURE_POWER_LCRIT }, + { "alarm", SENSORS_SUBFEATURE_POWER_ALARM }, + { "alarm_max", SENSORS_SUBFEATURE_POWER_MAX_ALARM }, + { "alarm_min", SENSORS_SUBFEATURE_POWER_MIN_ALARM }, + { "alarm_cap", SENSORS_SUBFEATURE_POWER_CAP_ALARM }, + { "alarm_crit", SENSORS_SUBFEATURE_POWER_CRIT_ALARM }, + { "alarm_lcrit", SENSORS_SUBFEATURE_POWER_LCRIT_ALARM }, + { NULL }, + }; + + return read_sensors(ctx, source, SENSORS_FEATURE_POWER, values); +} + +const td_source_impl sensors_power_source = { + .name = "sensors-power", + + // RRD Data Sources + .rrd_dss = { + { "average", "GAUGE", 0, -1, }, + { "average_highest", "GAUGE", 0, -1, }, + { "average_lowest", "GAUGE", 0, -1, }, + { "average_interval", "GAUGE", 0, -1, }, + { "input", "GAUGE", 0, -1, }, + { "input_highest", "GAUGE", 0, -1, }, + { "input_lowest", "GAUGE", 0, -1, }, + { "cap", "GAUGE", 0, -1, }, + { "cap_hyst", "GAUGE", 0, -1, }, + { "max", "GAUGE", 0, -1, }, + { "min", "GAUGE", 0, -1, }, + { "crit", "GAUGE", 0, -1, }, + { "lcrit", "GAUGE", 0, -1, }, + { "alarm", "GAUGE", 0, -1, }, + { "alarm_max", "GAUGE", 0, -1, }, + { "alarm_min", "GAUGE", 0, -1, }, + { "alarm_cap", "GAUGE", 0, -1, }, + { "alarm_emergency", "GAUGE", 0, -1, }, + { "alarm_lcrit", "GAUGE", 0, -1, }, + { NULL }, + }, + + // Methods + .heartbeat = sensors_power_heartbeat, +}; diff --git a/src/daemon/sources/sensors.h b/src/daemon/sources/sensors.h index 45c309f..4be195d 100644 --- a/src/daemon/sources/sensors.h +++ b/src/daemon/sources/sensors.h @@ -26,5 +26,6 @@ extern const td_source_impl sensors_input_source; extern const td_source_impl sensors_fan_source; extern const td_source_impl sensors_temp_source; +extern const td_source_impl sensors_power_source; #endif /* TELEMETRY_SOURCE_SENSORS_H */