]> git.ipfire.org Git - collecty.git/commitdiff
sources: sensors: Collect voltage/input sensors
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 23 Oct 2025 16:23:12 +0000 (16:23 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 23 Oct 2025 16:23:12 +0000 (16:23 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/sources.c
src/daemon/sources/sensors.c
src/daemon/sources/sensors.h

index 38ee8b58cd1049e2b06761ea272d04d3d13d0ec3..886e93a80dca124cd8c73600d94c092167a125b2 100644 (file)
@@ -89,6 +89,7 @@ static const td_source_impl* source_impls[] = {
 
        // sensors
 #ifdef HAVE_SENSORS
+       &sensors_input_source,
        &sensors_temp_source,
 #endif /* HAVE_SENSORS */
 
index a956d42bde2f1b68129409c4be57fa940e0f3295..0652a3715282bb206665e32ba250f7d4200d6745 100644 (file)
@@ -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 = {
index 5e6ec9d356c50ba9be699d79af64083fbfe9b3e8..48287934b265dc400d7554a150532f0d4dee5335 100644 (file)
@@ -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 */