report: add backend for reporting temperature sensors

This commit is contained in:
Lennart Poettering
2026-09-23 16:31:41 +02:00
committed by Luca Boccassi
parent 31bf94f87d
commit 186a8486fc
13 changed files with 527 additions and 0 deletions
@@ -110,6 +110,7 @@ INTROSPECTABLE=(
systemd-report-basic
systemd-report-cgroup
systemd-report-files
systemd-report-hwmon
systemd-report-sign-plain
systemd-report-sign-tpm2
systemd-report-sign-tsm
+31
View File
@@ -62,6 +62,37 @@ net_metrics="$(varlinkctl call --more --json=short /run/systemd/report/io.system
echo "$net_metrics" | grep '"name":"io.systemd.Network.Address"' | grep '"object":"lo"' | grep '"value":"192.0.2.1/32"' | grep '"family":"ipv4"' >/dev/null
ip address del 192.0.2.1/32 dev lo
# test io.systemd.HWMon Metrics
systemctl start systemd-report-hwmon.socket
varlinkctl info /run/systemd/report/io.systemd.HWMon
varlinkctl list-methods /run/systemd/report/io.systemd.HWMon
hwmon_describe="$(varlinkctl call --more /run/systemd/report/io.systemd.HWMon io.systemd.Metrics.Describe {})"
echo "$hwmon_describe" | jq --seq -r 'select(.name == "io.systemd.HWMon.TemperatureCelsius") | .type' | grep -wx gauge >/dev/null
# An empty result set is signalled through the io.systemd.Metrics.NoSuchMetric sentinel error, which is what
# VMs without any hwmon devices produce, hence treat it as success.
hwmon_metrics="$(varlinkctl call --more --graceful=io.systemd.Metrics.NoSuchMetric /run/systemd/report/io.systemd.HWMon io.systemd.Metrics.List {})"
# At most one row per readable, non-faulted temp<N>_input attribute in sysfs. A sensor may become
# transiently unreadable between the two samples, hence only check the bound. VMs typically expose no hwmon
# devices at all, in which case both counts are zero.
hwmon_expected=0
for f in /sys/class/hwmon/hwmon*/temp*_input; do
hwmon_fault="${f%_input}_fault"
if [[ -f "$hwmon_fault" ]] && [[ "$(cat "$hwmon_fault")" == 1 ]]; then
continue
fi
if cat "$f" >/dev/null 2>&1; then
hwmon_expected=$((hwmon_expected + 1))
fi
done
hwmon_reported="$(echo "$hwmon_metrics" | jq --seq -r 'select(.name == "io.systemd.HWMon.TemperatureCelsius") | .fields.sensor' | wc -l)"
[[ "$hwmon_reported" -le "$hwmon_expected" ]]
if [[ "$hwmon_reported" -gt 0 ]]; then
# Every row must carry a numeric value, an object and a sensor field of the form temp<N>
[[ "$(echo "$hwmon_metrics" | jq --seq -r 'select(.name == "io.systemd.HWMon.TemperatureCelsius") | ((.value | type) == "number") and ((.object | type) == "string") and (.fields.sensor | test("^temp[0-9]+$")) | tostring' | sort -u)" == "true" ]]
fi
"$REPORT" describe io.systemd.HWMon
"$REPORT" metrics io.systemd.HWMon
# test io.systemd.Basic Metrics
# ensure the socket is running, as some distros don't enable it by default
systemctl start systemd-report-basic.socket