From: Michael Tremer Date: Thu, 23 Oct 2025 16:23:12 +0000 (+0000) Subject: sources: sensors: Collect voltage/input sensors X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e8219f42fe33de2b4e82ef51bd1df1254b30e580;p=collecty.git sources: sensors: Collect voltage/input sensors Signed-off-by: Michael Tremer --- diff --git a/src/daemon/sources.c b/src/daemon/sources.c index 38ee8b5..886e93a 100644 --- a/src/daemon/sources.c +++ b/src/daemon/sources.c @@ -89,6 +89,7 @@ static const td_source_impl* source_impls[] = { // sensors #ifdef HAVE_SENSORS + &sensors_input_source, &sensors_temp_source, #endif /* HAVE_SENSORS */ diff --git a/src/daemon/sources/sensors.c b/src/daemon/sources/sensors.c index a956d42..0652a37 100644 --- a/src/daemon/sources/sensors.c +++ b/src/daemon/sources/sensors.c @@ -230,8 +230,67 @@ static int read_sensors(td_ctx* ctx, const sensors_chip_name* chip, return 0; } +/* + (Voltage) Input +*/ +static int read_input_sensors(td_ctx* ctx, td_source* source, const sensors_chip_name* chip, + const sensors_feature* feature, td_metrics* metrics) { + sensors_value values[] = { + { "current", SENSORS_SUBFEATURE_IN_INPUT }, + { "min", SENSORS_SUBFEATURE_IN_MIN }, + { "max", SENSORS_SUBFEATURE_IN_MAX }, + { "lcrit", SENSORS_SUBFEATURE_IN_LCRIT }, + { "crit", SENSORS_SUBFEATURE_IN_CRIT }, + { "average", SENSORS_SUBFEATURE_IN_LCRIT }, + { "lowest", SENSORS_SUBFEATURE_IN_LOWEST }, + { "highest", SENSORS_SUBFEATURE_IN_HIGHEST }, + { "alarm", SENSORS_SUBFEATURE_IN_ALARM }, + { "alarm_max", SENSORS_SUBFEATURE_IN_MAX_ALARM }, + { "alarm_min", SENSORS_SUBFEATURE_IN_MIN_ALARM }, + { "alarm_crit", SENSORS_SUBFEATURE_IN_CRIT_ALARM }, + { "alarm_lcrit", SENSORS_SUBFEATURE_IN_LCRIT_ALARM }, + { "beep", SENSORS_SUBFEATURE_IN_BEEP }, + { NULL }, + }; -static int read_temp_sensor(td_ctx* ctx, td_source* source, const sensors_chip_name* chip, + // Read values + return read_sensors(ctx, chip, feature, metrics, values); +} + +static int sensors_input_heartbeat(td_ctx* ctx, td_source* source) { + return find_sensors(ctx, source, SENSORS_FEATURE_IN, read_input_sensors); +} + +const td_source_impl sensors_input_source = { + .name = "sensors-input", + + // RRD Data Sources + .rrd_dss = { + { "current", "GAUGE", 0, -1, }, + { "min", "GAUGE", 0, -1, }, + { "max", "GAUGE", 0, -1, }, + { "lcrit", "GAUGE", 0, -1, }, + { "crit", "GAUGE", 0, -1, }, + { "average", "GAUGE", 0, -1, }, + { "lowest", "GAUGE", 0, -1, }, + { "highest", "GAUGE", 0, -1, }, + { "alarm", "GAUGE", 0, -1, }, + { "alarm_max", "GAUGE", 0, -1, }, + { "alarm_min", "GAUGE", 0, -1, }, + { "alarm_crit", "GAUGE", 0, -1, }, + { "alarm_lcrit", "GAUGE", 0, -1, }, + { "beep", "GAUGE", 0, -1, }, + { NULL }, + }, + + // Methods + .heartbeat = sensors_input_heartbeat, +}; + +/* + Temperature +*/ +static int read_temp_sensors(td_ctx* ctx, td_source* source, const sensors_chip_name* chip, const sensors_feature* feature, td_metrics* metrics) { sensors_value values[] = { { "current", SENSORS_SUBFEATURE_TEMP_INPUT }, @@ -264,14 +323,7 @@ static int read_temp_sensor(td_ctx* ctx, td_source* source, const sensors_chip_n } static int sensors_temp_heartbeat(td_ctx* ctx, td_source* source) { - int r; - - // Find temperature sensors - r = find_sensors(ctx, source, SENSORS_FEATURE_TEMP, read_temp_sensor); - if (r < 0) - return r; - - return 0; + return find_sensors(ctx, source, SENSORS_FEATURE_TEMP, read_temp_sensors); } const td_source_impl sensors_temp_source = { diff --git a/src/daemon/sources/sensors.h b/src/daemon/sources/sensors.h index 5e6ec9d..4828793 100644 --- a/src/daemon/sources/sensors.h +++ b/src/daemon/sources/sensors.h @@ -23,6 +23,7 @@ #include "../source.h" +extern const td_source_impl sensors_input_source; extern const td_source_impl sensors_temp_source; #endif /* TELEMETRY_SOURCE_SENSORS_H */