From 5420b5155d9f5a2fe1d0b65e51c5f44f7a6bf3a4 Mon Sep 17 00:00:00 2001 From: dev Date: Mon, 9 Nov 2026 11:24:54 +0200 Subject: [PATCH 1/3] fanctrlplus2: show a sensor that reads the same for hours MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some boards fill a temperature register with a fixed value; ACPI thermal zones reading 27.8 °C (3010 deci-kelvin) are a common case. Such a sensor gives a reading, so the missing-sensor warning never sees it, and a curve on it never moves. Each loop now tracks its CPU and aux sensors. One that has not changed by even 1 °C for 6 hours of the loop's readings, while another source of the same fan (CPU, aux or a disk group) moved by 10 °C or more, is shown as such beside its setting on the settings page. A per-fan Frozen Sensors switch under Syslog & Alerts, on by default like Problem Alerts, also sends one Unraid warning per sensor per boot. Fan control is unchanged. The tracking is kept on tmpfs, so applying settings does not restart it. --- README.md | 1 + .../plugins/fanctrlplus2/css/fcp.base.css | 13 +- .../plugins/fanctrlplus2/fanctrlplus2.page | 12 +- .../plugins/fanctrlplus2/include/Common.php | 32 ++++ .../fanctrlplus2/include/ConfigBackup.php | 2 +- .../fanctrlplus2/include/FanBlockRender.php | 24 ++- .../fanctrlplus2/include/FanctrlLogic.php | 8 +- .../include/update.fanctrlplus2.php | 3 +- .../scripts/disk_group_control.sh | 143 ++++++++++++++++++ .../fanctrlplus2/scripts/fanctrlplus2_loop.sh | 23 +++ tests/frozen_sensor_state_test.php | 71 +++++++++ tests/frozen_sensor_test.sh | 129 ++++++++++++++++ 12 files changed, 449 insertions(+), 12 deletions(-) create mode 100644 tests/frozen_sensor_state_test.php create mode 100644 tests/frozen_sensor_test.sh diff --git a/README.md b/README.md index c17ed31..f6a49ca 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ Configuration is done through a user-friendly interface, with custom thresholds, - Sends Unraid notifications when a fan has a problem, while fan control keeps running. A fan gets one warning when, for at least 30 seconds, its PWM controller disappears, the BIOS or another program takes it over, the controller reports a speed 10 or more percentage points away from the one set, or the fan reports 0 RPM while set above 40% after spinning earlier. A fan whose controller is missing when fan control starts also gets one warning. At boot, fan control waits for Unraid to finish installing plugins (signalled by emhttpd starting, or after 5 minutes at most), so a controller whose driver comes from another plugin is normally there by then. A controller still missing gets 5 more minutes for its driver to load before it warns. A notice follows once the problem has stayed away for 30 seconds. A configured CPU or auxiliary sensor without a reading for at least 60 seconds also gets one warning per fan per boot, since the fan cannot react to it and, if nothing else reads, stays at its Idle or Min Speed. Alerts are on by default and can be turned off per fan under Syslog & Alerts, for example for a controller with only a few speed steps that never reads back the exact speed set A PWM mismatch warning also reports a substantial RPM response to a recent speed change when observed. This suggests, but does not prove, that the fan responded despite the PWM readback. The PWM mismatch grace period restarts when the requested speed changes, so readings from different targets do not combine into one warning. +- Shows beside a configured CPU or auxiliary sensor when its reading has not changed by even 1 °C for 6 hours while another source of the same fan moved by 10 °C or more: such a sensor may report a fixed placeholder (some boards fill ACPI thermal zones with 27.8 °C) rather than a measurement. A per-fan Frozen Sensors switch under Syslog & Alerts, on by default, also sends one Unraid warning per sensor per boot. Fan control is unchanged - Give each disk group, CPU rule, and auxiliary rule its own 2–8 point fan curve with linear or stepped control - Keep absolute point speeds when changing the normal output cap; optionally override that cap at an emergency temperature - Configure cooling hysteresis to avoid repeated speed changes near temperature boundaries diff --git a/src/usr/local/emhttp/plugins/fanctrlplus2/css/fcp.base.css b/src/usr/local/emhttp/plugins/fanctrlplus2/css/fcp.base.css index 3af7fa1..ef27135 100644 --- a/src/usr/local/emhttp/plugins/fanctrlplus2/css/fcp.base.css +++ b/src/usr/local/emhttp/plugins/fanctrlplus2/css/fcp.base.css @@ -287,6 +287,17 @@ white-space: nowrap; } .fcp-nct6687-notice { justify-content: flex-start; } +/* A conclusion about a configured sensor, shown beside its setting. */ +.fcp-sensor-state { + display: block; + max-width: 300px; + margin-top: 4px; + padding-left: 6px; + border-left: 3px solid #d79b00; + font-size: 12px; + line-height: 1.4; + white-space: normal; +} .fcp-nct6687-notice code.fcp-cmd { display: block; margin: 4px 0; user-select: all; } /* ===== Sort toggle ===== */ @@ -568,7 +579,7 @@ dt.containerSettingsDt { .fcp-airflow-switch{ display: none; } .fcp-history-switch{ display: none; } -.syslog-switch, .notify-switch{ display: none; } +.syslog-switch, .notify-switch, .frozen-switch{ display: none; } .switch-button-label{ font-size: 12px; } .switch-button-label.on{ display: none; } .switch-button-background.checked ~ .switch-button-label.on{ display: inline; } diff --git a/src/usr/local/emhttp/plugins/fanctrlplus2/fanctrlplus2.page b/src/usr/local/emhttp/plugins/fanctrlplus2/fanctrlplus2.page index 9d6b0f3..af3bec6 100644 --- a/src/usr/local/emhttp/plugins/fanctrlplus2/fanctrlplus2.page +++ b/src/usr/local/emhttp/plugins/fanctrlplus2/fanctrlplus2.page @@ -1282,8 +1282,8 @@ $(function() { $area.find('.switch-button-button').css('left', checked ? '12px' : '-1px'); // Persist the relevant switch. - if ($input.hasClass('syslog-switch') || $input.hasClass('notify-switch')) { - saveFanSwitchState($input.hasClass('syslog-switch') ? 'setsyslog' : 'setnotify', $input.data('cfg'), checked); + if ($input.hasClass('syslog-switch') || $input.hasClass('notify-switch') || $input.hasClass('frozen-switch')) { + saveFanSwitchState($input.hasClass('syslog-switch') ? 'setsyslog' : $input.hasClass('notify-switch') ? 'setnotify' : 'setfrozennotify', $input.data('cfg'), checked); } else if ($input.hasClass('fcp-airflow-switch')) { saveAirflowSwitchState(checked); } else if ($input.hasClass('fcp-history-switch')) { @@ -1292,7 +1292,7 @@ $(function() { }); // Shared change handler for the per-fan and FCP Airflow/History switches. - $(document).on('change', '.syslog-switch, .notify-switch, .fcp-airflow-switch, .fcp-history-switch', function() { + $(document).on('change', '.syslog-switch, .notify-switch, .frozen-switch, .fcp-airflow-switch, .fcp-history-switch', function() { var checked = $(this).prop('checked'); var $area = $(this).closest('.switch-area'); @@ -2076,6 +2076,7 @@ $(function() {

Note: The plugin only writes to syslog when the PWM value changes by more than 5 compared to the previous value — small changes are ignored to reduce log noise.

Problem Alerts are also enabled by default. Fan control keeps running either way; the alerts only send Unraid notifications. A fan gets one warning when, for at least 30 seconds, its PWM controller has disappeared, the BIOS or another program has taken it over, its controller reports a speed 10 or more percentage points away from the one set, or it reports 0 RPM while set above 40% after spinning earlier. A fan whose controller is missing when fan control starts, and a configured sensor without a reading for 60 seconds, also warn. Once the problem has stayed away for 30 seconds, a notice says so. Turn the alerts off for a fan whose controller raises false alarms, such as one with only a few speed steps.

When RPM has changed in the requested direction at least 30 seconds after a substantial speed change, a PWM mismatch warning includes that observation. It suggests that the fan may have responded despite the reported PWM; it does not prove which controller changed the fan.

+

Frozen Sensors: a CPU or auxiliary sensor whose reading has not changed by even 1 °C for 6 hours, while another source of the same fan moved by 10 °C or more, may report a fixed placeholder rather than a measurement (some boards fill ACPI thermal zones with 27.8 °C). The settings page always shows this beside the sensor; this switch, enabled by default, also sends one Unraid warning per sensor per boot. Fan control is unchanged either way.

@@ -2087,6 +2088,7 @@ $(function() { Configured Fan Syslog Problem Alerts + Frozen Sensors @@ -2100,7 +2102,7 @@ $(function() { ?> - 'syslog', 'notify' => 'notify', 'frozen_notify' => 'frozen'] as $switch => $switch_class): $is_on = ($cfg[$switch] ?? "1") != "0"; $switch_id = "$switch-switch-" . htmlspecialchars($cfg['custom']); ?> @@ -2112,7 +2114,7 @@ $(function() { > ON diff --git a/src/usr/local/emhttp/plugins/fanctrlplus2/include/Common.php b/src/usr/local/emhttp/plugins/fanctrlplus2/include/Common.php index dca6dab..b907be5 100644 --- a/src/usr/local/emhttp/plugins/fanctrlplus2/include/Common.php +++ b/src/usr/local/emhttp/plugins/fanctrlplus2/include/Common.php @@ -63,6 +63,38 @@ function fcp_parse_history_line(string $line): ?array { ]; } +// Sensors a fan's loop found reading the same for hours while another of the +// fan's sources moved (fcp_track_frozen in disk_group_control.sh), keyed by +// source: cpu, or an aux sensor. Each line is +// "SOURCE|VALUE|SINCE|LAST|OTHER|LO|HI". A conclusion the loop has not +// renewed for $stale seconds is left out: the loop is no longer running. +function fcp_frozen_sensors(string $file, int $stale, ?int $now = null): array { + $now = $now ?? time(); + $found = []; + foreach (is_file($file) ? (file($file, FILE_IGNORE_NEW_LINES) ?: []) : [] as $line) { + $parts = explode('|', $line); + if (count($parts) !== 7) continue; + [$src, $value, $since, $last, $other, $lo, $hi] = $parts; + if ($src === '' || $other === '') continue; + foreach ([$value, $since, $last, $lo, $hi] as $number) { + if (!ctype_digit($number)) continue 2; + } + if ($now - (int)$last > $stale) continue; + $found[$src] = [ + 'value' => (int)$value, 'since' => (int)$since, 'last' => (int)$last, + 'other' => $other, 'lo' => (int)$lo, 'hi' => (int)$hi, + ]; + } + return $found; +} + +// The state the settings page shows beside the sensor. $other is how the +// page names the source that moved. +function fcp_frozen_text(array $frozen, string $other): string { + $hours = intdiv($frozen['last'] - $frozen['since'], 3600); + return "Unchanged at {$frozen['value']} °C for $hours h while $other varied {$frozen['lo']}–{$frozen['hi']} °C: may be a fixed placeholder."; +} + // ============================= // Migrate hwmonX configuration and label paths. // ============================= diff --git a/src/usr/local/emhttp/plugins/fanctrlplus2/include/ConfigBackup.php b/src/usr/local/emhttp/plugins/fanctrlplus2/include/ConfigBackup.php index 99dd8ef..9ac096a 100644 --- a/src/usr/local/emhttp/plugins/fanctrlplus2/include/ConfigBackup.php +++ b/src/usr/local/emhttp/plugins/fanctrlplus2/include/ConfigBackup.php @@ -100,7 +100,7 @@ function fcp_backup_assignments(string $text): array { function fcp_validate_fan_config(string $text): array { $values = fcp_backup_assignments($text); - $boolean = ['service','syslog','notify','log_enable','cpu_enable','aux_enable']; + $boolean = ['service','syslog','notify','frozen_notify','log_enable','cpu_enable','aux_enable']; $numeric = ['pwm','max','idle','idle_percent','low','high','interval','interval_sec','disk_group_count','cpu_min_temp','cpu_max_temp','aux_min_temp','aux_max_temp']; $string = ['custom','label','controller','controller_identity','fan','disks','cpu_sensor','aux_sensor']; foreach ($values as $key=>$value) { diff --git a/src/usr/local/emhttp/plugins/fanctrlplus2/include/FanBlockRender.php b/src/usr/local/emhttp/plugins/fanctrlplus2/include/FanBlockRender.php index 6f2696a..dcd302c 100644 --- a/src/usr/local/emhttp/plugins/fanctrlplus2/include/FanBlockRender.php +++ b/src/usr/local/emhttp/plugins/fanctrlplus2/include/FanBlockRender.php @@ -148,7 +148,23 @@ function fcp_saved_sensor_text(string $sensor): string { return (fcp_sensor_missing($sensor) ? 'Not detected: ' : '') . $sensor; } -function render_fan_block($cfg, $i, $pwms, $disks, $pwm_labels, $cpu_sensors, $aux_sensors = []) { +// $frozen: the fan's frozen-sensor conclusions (fcp_frozen_sensors), read +// from its loop's runtime file when not given. +function render_fan_block($cfg, $i, $pwms, $disks, $pwm_labels, $cpu_sensors, $aux_sensors = [], $frozen = null) { + $frozen ??= fcp_frozen_sensors('/var/tmp/fanctrlplus2/frozen_' . basename((string)($cfg['custom'] ?? '')), + 2 * cfg_interval_seconds($cfg) + 300); + // Sources as the state beside a sensor names them, as in the fan's history. + $aux_names = []; + foreach ($aux_sensors as $entries) { + foreach ($entries as $sensor) $aux_names[$sensor['path']] = preg_replace('/\s*\(-?[\d.]+°C\)$/u', '', $sensor['label']); + } + $source_name = function (string $src) use ($cfg, $aux_names): string { + if ($src === 'cpu') return 'CPU'; + if (!preg_match('/^disk:(\d+)$/', $src, $m)) return $aux_names[$src] ?? $src; + if (intval($cfg['disk_group_count'] ?? 0) === 0) return 'Disk'; + $name = (string)($cfg["disk_group_{$m[1]}_name"] ?? ''); + return 'Disk: ' . ($name !== '' ? $name : 'Group ' . ($m[1] + 1)); + }; $curve_error = ''; try { $curve_rules = fcp_curve_rules($cfg); } catch (InvalidArgumentException $error) { $curve_rules = null; $curve_error = $error->getMessage(); } @@ -368,6 +384,9 @@ class="interval-input fcp-interval-input" + + + @@ -414,6 +433,9 @@ class="interval-input fcp-interval-input" + + + diff --git a/src/usr/local/emhttp/plugins/fanctrlplus2/include/FanctrlLogic.php b/src/usr/local/emhttp/plugins/fanctrlplus2/include/FanctrlLogic.php index eeb0d81..0053020 100644 --- a/src/usr/local/emhttp/plugins/fanctrlplus2/include/FanctrlLogic.php +++ b/src/usr/local/emhttp/plugins/fanctrlplus2/include/FanctrlLogic.php @@ -35,7 +35,7 @@ $op = $_GET['op'] ?? $_POST['op'] ?? ''; // Serialize restore/export with every HTTP writer of these configuration files. -if (in_array($op, ['savelabel','newtemp','delete','setsyslog','setnotify','saveorder','start','stop','fcp_airflow_toggle','fcp_history_toggle'], true)) { +if (in_array($op, ['savelabel','newtemp','delete','setsyslog','setnotify','setfrozennotify','saveorder','start','stop','fcp_airflow_toggle','fcp_history_toggle'], true)) { try { $config_lock = fcp_config_lock($cfg_dir); } catch (Throwable $error) { http_response_code(500); json_response(['status'=>'error','message'=>$error->getMessage()]); } register_shutdown_function(function () use ($config_lock) { @@ -271,10 +271,12 @@ function () use ($service, &$was_running) { if ($was_running) $service('start'); echo render_disk_group_row($fan_index, $group_index, $empty_group, $disks); exit; - // Per-fan switches: Syslog, and Problem Alerts (read by the loop on each alert). + // Per-fan switches: Syslog, Problem Alerts and Frozen Sensors alerts (the + // alert switches are read by the loop on each alert). case 'setsyslog': case 'setnotify': - $key = $op === 'setsyslog' ? 'syslog' : 'notify'; + case 'setfrozennotify': + $key = ['setsyslog' => 'syslog', 'setnotify' => 'notify', 'setfrozennotify' => 'frozen_notify'][$op]; $cfg_file = basename($_POST['cfg']); $enabled = isset($_POST['enabled']) && $_POST['enabled'] == 1 ? 1 : 0; diff --git a/src/usr/local/emhttp/plugins/fanctrlplus2/include/update.fanctrlplus2.php b/src/usr/local/emhttp/plugins/fanctrlplus2/include/update.fanctrlplus2.php index 5614374..96f7328 100644 --- a/src/usr/local/emhttp/plugins/fanctrlplus2/include/update.fanctrlplus2.php +++ b/src/usr/local/emhttp/plugins/fanctrlplus2/include/update.fanctrlplus2.php @@ -275,9 +275,10 @@ 'interval' => (string)max(1, (int)ceil($interval_seconds / 60)), 'disks' => $legacy_disks, 'disk_group_count' => (string)$disk_group_count, - // Per-fan switches set outside this form: keep them, both default on. + // Per-fan switches set outside this form: keep them, all default on. 'syslog' => (string)($previous['syslog'] ?? '1'), 'notify' => (string)($previous['notify'] ?? '1'), + 'frozen_notify' => (string)($previous['frozen_notify'] ?? '1'), 'cpu_enable' => $cpu_enable, 'cpu_sensor' => $cpu_sensor, 'cpu_min_temp' => $legacy['cpu_min_temp'], diff --git a/src/usr/local/emhttp/plugins/fanctrlplus2/scripts/disk_group_control.sh b/src/usr/local/emhttp/plugins/fanctrlplus2/scripts/disk_group_control.sh index 476c770..9819a8b 100644 --- a/src/usr/local/emhttp/plugins/fanctrlplus2/scripts/disk_group_control.sh +++ b/src/usr/local/emhttp/plugins/fanctrlplus2/scripts/disk_group_control.sh @@ -559,3 +559,146 @@ fcp_notify_missing() { -d "No reading for at least $fcp_missing_grace_seconds seconds from: ${sensors%, }. The fan cannot react to these sensors while they are unread, and stays at its Idle or Min Speed when no other source has a reading." \ || rm -f "$flag" } + +# ===== Configured sensors that never change ===== +# Some firmware fills a temperature register with a fixed value instead of a +# measurement; ACPI thermal zones reading 27.8 °C (3010 deci-kelvin) are a +# common case. Such a sensor reads, so the missing-sensor warning above never +# sees it, but a fan curve on it never moves. A CPU or aux sensor of a fan is +# taken for one when its reading has not changed by even one degree for +# fcp_frozen_window_seconds of this loop's own readings, while another source +# of the same fan moved by fcp_frozen_swing degrees or more in that time. The +# window is long enough for a room's ambient temperature to drift by a degree +# over a day and spans several readings at the longest interval; the swing +# keeps a steady sensor in a steady machine from counting. The conclusion is +# only shown and, by the fan's "Frozen Sensors" switch (frozen_notify=0 in its +# cfg), notified: fan control is unchanged. +fcp_frozen_window_seconds=21600 +fcp_frozen_swing=10 + +# Source -> "VALUE|SINCE|LAST": the reading of its current unchanged stretch, +# when that began, and when it was last read. "SOURCE>OTHER" -> "LO|HI": how +# far another source of the fan moved during that stretch. +declare -gA fcp_frozen_run=() fcp_frozen_range=() +# This round's conclusions, "SOURCE|VALUE|SINCE|LAST|OTHER|LO|HI". +fcp_frozen_found=() + +# Records one round of readings and sets fcp_frozen_found. The arguments after +# the time and the gap are "SOURCE|TEMP|WATCHED" readings: every source that +# gave one (cpu, each aux sensor, disk:), WATCHED being 1 for the +# sensors that can be judged (CPU and aux). A source read again only after +# more than gap seconds starts over: the loop was not running in between. Call +# it in the loop's own shell, not in $(...): its state lives in these globals. +fcp_track_frozen() { + local now="$1" gap="$2" reading src temp watched other value since last lo hi key best span + shift 2 + local -A temps=() judged=() + fcp_frozen_found=() + for reading in "$@"; do + IFS='|' read -r src temp watched <<< "$reading" + [[ "$temp" =~ ^[0-9]+$ ]] || continue + temps[$src]=$temp + [[ "$watched" == 1 ]] && judged[$src]=1 + done + for src in "${!judged[@]}"; do + temp=${temps[$src]} + IFS='|' read -r value since last <<< "${fcp_frozen_run[$src]:-}" + if [[ "$value" != "$temp" ]] || (( now - last > gap )); then + value=$temp since=$now + for key in "${!fcp_frozen_range[@]}"; do + [[ "$key" == "$src>"* ]] && unset 'fcp_frozen_range[$key]' + done + fi + fcp_frozen_run[$src]="$value|$since|$now" + best="" + for other in "${!temps[@]}"; do + [[ "$other" == "$src" ]] && continue + IFS='|' read -r lo hi <<< "${fcp_frozen_range[$src>$other]:-}" + temp=${temps[$other]} + [[ -z "$lo" ]] || (( temp < lo )) && lo=$temp + [[ -z "$hi" ]] || (( temp > hi )) && hi=$temp + fcp_frozen_range[$src>$other]="$lo|$hi" + done + (( now - since >= fcp_frozen_window_seconds )) || continue + # The source that moved the most is the one named. + span=$(( fcp_frozen_swing - 1 )) + for key in "${!fcp_frozen_range[@]}"; do + [[ "$key" == "$src>"* ]] || continue + IFS='|' read -r lo hi <<< "${fcp_frozen_range[$key]}" + (( hi - lo > span )) || continue + span=$(( hi - lo )) + best="${key#"$src>"}|$lo|$hi" + done + [[ -n "$best" ]] && fcp_frozen_found+=("$src|$value|$since|$now|$best") + done + # A source not read for longer than the gap starts over anyway. + for src in "${!fcp_frozen_run[@]}"; do + IFS='|' read -r value since last <<< "${fcp_frozen_run[$src]}" + (( now - last > gap )) || continue + unset 'fcp_frozen_run[$src]' + for key in "${!fcp_frozen_range[@]}"; do + [[ "$key" == "$src>"* ]] && unset 'fcp_frozen_range[$key]' + done + done +} + +# The tracking survives a loop restart (applying settings restarts every +# loop) in a RAM file: "run|SOURCE|VALUE|SINCE|LAST" and "range|SOURCE>OTHER|LO|HI". +fcp_frozen_save() { + local file="$1" key tmp="${1}.tmp.$$" + { + for key in "${!fcp_frozen_run[@]}"; do printf 'run|%s|%s\n' "$key" "${fcp_frozen_run[$key]}"; done + for key in "${!fcp_frozen_range[@]}"; do printf 'range|%s|%s\n' "$key" "${fcp_frozen_range[$key]}"; done + } > "$tmp" 2>/dev/null && mv -f "$tmp" "$file" 2>/dev/null +} + +fcp_frozen_load() { + local file="$1" kind key rest + fcp_frozen_run=() + fcp_frozen_range=() + [[ -f "$file" ]] || return 0 + while IFS='|' read -r kind key rest; do + case "$kind" in + run) [[ "$rest" =~ ^[0-9]+\|[0-9]+\|[0-9]+$ ]] && fcp_frozen_run[$key]=$rest ;; + range) [[ "$rest" =~ ^[0-9]+\|[0-9]+$ ]] && fcp_frozen_range[$key]=$rest ;; + esac + done < "$file" +} + +# The conclusions, one fcp_frozen_found entry per line, for the settings page. +fcp_frozen_publish() { + local file="$1" tmp="${1}.tmp.$$" + { (( ${#fcp_frozen_found[@]} )) && printf '%s\n' "${fcp_frozen_found[@]}"; } > "$tmp" 2>/dev/null + mv -f "$tmp" "$file" 2>/dev/null +} + +# A source key as a notification names it. +fcp_frozen_label() { + case "$1" in + cpu) printf 'the CPU sensor %s' "${cpu_sensor:-}" ;; + disk:*) history_source_label "$1" ;; + *) printf '%s' "$1" ;; + esac +} + +fcp_frozen_alerts_enabled() { + (unset frozen_notify; source "${cfg_file:-}" >/dev/null 2>&1; [[ "${frozen_notify:-1}" != 0 ]]) +} + +# One Unraid warning per sensor per boot. The flag file on tmpfs lists the +# sensors already warned about; a failed notification leaves a sensor out, +# so the next round tries again. +fcp_notify_frozen() { + local name="$1" flag="$2" found src value since last other lo hi hours + shift 2 + for found in "$@"; do + IFS='|' read -r src value since last other lo hi <<< "$found" + grep -qxF -- "$src" "$flag" 2>/dev/null && continue + fcp_frozen_alerts_enabled || return 0 + touch "$flag" 2>/dev/null || return 0 + hours=$(( (last - since) / 3600 )) + fcp_notify -i warning -s "Fan $name has a temperature sensor that does not change" \ + -d "$(fcp_frozen_label "$src") has read $value °C for $hours hours while $(fcp_frozen_label "$other") varied $lo–$hi °C. It may report a fixed value rather than a measurement. Fan control is unchanged." && + printf '%s\n' "$src" >> "$flag" + done +} diff --git a/src/usr/local/emhttp/plugins/fanctrlplus2/scripts/fanctrlplus2_loop.sh b/src/usr/local/emhttp/plugins/fanctrlplus2/scripts/fanctrlplus2_loop.sh index acdf5c2..a8df13a 100644 --- a/src/usr/local/emhttp/plugins/fanctrlplus2/scripts/fanctrlplus2_loop.sh +++ b/src/usr/local/emhttp/plugins/fanctrlplus2/scripts/fanctrlplus2_loop.sh @@ -68,6 +68,11 @@ hist_file="/var/tmp/${plugin}/history_${plugin}_${custom}" # does not flip the attribution of an ongoing PWM tie (see history_pick_source). prev_hist_src=$(tail -n 1 "$hist_file" 2>/dev/null | cut -d'|' -f2) +# Sensors that have read the same for hours (fcp_track_frozen), carried over +# from before a restart. +frozen_state="/var/tmp/${plugin}/frozen_state_${custom}" +fcp_frozen_load "$frozen_state" + # Whether the last controller write, and the last curve-state snapshot, failed. # Each is logged once per stretch, not every round. write_failing=0 @@ -262,5 +267,23 @@ while true; do fcp_notify_missing "$custom" "/var/tmp/${plugin}/sensor_missing_${custom}" "${fcp_missing_overdue[@]}" fi + # Sensors that read the same for hours while another source of this fan + # moved: shown on the settings page, and warned about once if switched on. + frozen_readings=() + (( cpu_sampled && cpu_usable )) && frozen_readings+=("cpu|$cpu_temp|1") + while IFS= read -r reading; do + [[ -n "$reading" ]] && frozen_readings+=("$reading|1") + done <<< "$aux_readings" + for g in "${!fcp_disk_temps[@]}"; do + frozen_readings+=("disk:$g|${fcp_disk_temps[$g]}|0") + done + printf -v frozen_now '%(%s)T' -1 + fcp_track_frozen "$frozen_now" $(( 2 * $(interval_seconds) + 60 )) "${frozen_readings[@]}" + fcp_frozen_save "$frozen_state" + fcp_frozen_publish "/var/tmp/${plugin}/frozen_${custom}" + if (( ${#fcp_frozen_found[@]} )); then + fcp_notify_frozen "$custom" "/var/tmp/${plugin}/sensor_frozen_${custom}" "${fcp_frozen_found[@]}" + fi + sleep "$(interval_seconds)" done diff --git a/tests/frozen_sensor_state_test.php b/tests/frozen_sensor_state_test.php new file mode 100644 index 0000000..5be10d0 --- /dev/null +++ b/tests/frozen_sensor_state_test.php @@ -0,0 +1,71 @@ + 'fanctrlplus2_Bay.cfg', 'custom' => 'Bay', 'cpu_enable' => '1', 'aux_enable' => '1', + 'cpu_sensor' => '/sys/class/hwmon/hwmon4/temp1_input', 'aux_sensor' => "$acpi,custom:ambient", + 'disk_group_count' => '1', 'disk_group_0_name' => 'NVMe', 'disk_group_0_disks' => 'nvme0']; +$cpu = ['/sys/class/hwmon/hwmon4/temp1_input' => 'coretemp - Package id 0 (55°C)']; +$aux = ['acpitz' => [['path' => $acpi, 'label' => 'acpitz - temp1 (27.8°C)']], 'Custom Sensors' => [['path' => 'custom:ambient', 'label' => 'ambient (24°C)']]]; +$block = render_fan_block($cfg, 0, [], [], [], $cpu, $aux, $frozen); +$check(str_contains($block, 'Unchanged at 41 °C for 6 h while Disk: NVMe varied 30–42 °C: may be a fixed placeholder.'), + 'The CPU sensor shows its state, naming the disk group that moved.'); +$check(str_contains($block, 'acpitz - temp1: Unchanged at 27 °C for 6 h while CPU varied 48–71 °C: may be a fixed placeholder.'), + 'An aux sensor shows its state, named as the list names it.'); +$check(substr_count($block, 'fcp-sensor-state') === 2, 'A sensor without a conclusion shows nothing.'); +$check(!str_contains(render_fan_block($cfg, 0, [], [], [], $cpu, $aux, []), 'fcp-sensor-state'), 'No conclusions, no state.'); +$check(!str_contains(render_fan_block(array_replace($cfg, ['aux_sensor' => 'custom:ambient']), 0, [], [], [], $cpu, $aux, $frozen), 'acpitz - temp1:'), + 'A sensor no longer selected for the fan shows no state.'); + +// The switch: one more column of the per-fan alert switches, on by default. +$page = file_get_contents("$sourceRoot/fanctrlplus2.page"); +$logic = file_get_contents("$sourceRoot/include/FanctrlLogic.php"); +$update = file_get_contents("$sourceRoot/include/update.fanctrlplus2.php"); +$check(str_contains($page, 'Frozen Sensors') && str_contains($page, "'frozen_notify' => 'frozen'") && str_contains($page, "hasClass('frozen-switch')"), + 'Syslog & Alerts must have a Frozen Sensors switch per fan.'); +$check(str_contains($page, "'setfrozennotify'") && str_contains($logic, "'setfrozennotify' => 'frozen_notify'"), + 'The switch must be saved under its own key.'); +$check(str_contains($update, "'frozen_notify' => (string)(\$previous['frozen_notify'] ?? '1')"), + 'Saving the fan settings must keep the switch, on when never set.'); +$fan = "custom=\"Bay\"\nfrozen_notify=\"0\"\n"; +try { $check(fcp_validate_fan_config($fan)['frozen_notify'] === '0', 'A backup must carry the switch.'); } +catch (InvalidArgumentException $error) { $check(false, 'A backup with the switch must restore: '.$error->getMessage()); } +$rejected = false; +try { fcp_validate_fan_config("custom=\"Bay\"\nfrozen_notify=\"2\"\n"); } catch (InvalidArgumentException $error) { $rejected = true; } +$check($rejected, 'The switch is on or off.'); + +exec('rm -rf '.escapeshellarg($root)); + +if ($failures) { + fwrite(STDERR, implode("\n", $failures)."\n"); + exit(1); +} + +echo "frozen sensor state tests passed\n"; diff --git a/tests/frozen_sensor_test.sh b/tests/frozen_sensor_test.sh new file mode 100644 index 0000000..86018b8 --- /dev/null +++ b/tests/frozen_sensor_test.sh @@ -0,0 +1,129 @@ +#!/bin/bash +# A configured sensor that reads the same for hours while another source of +# the same fan moves (fcp_track_frozen) and its one warning per boot. + +set -u + +root=$(cd "$(dirname "$0")/.." && pwd) +tmp=$(mktemp -d) +trap 'rm -rf "$tmp"' EXIT + +fcp_notify_bin="$tmp/notify" +source "$root/src/usr/local/emhttp/plugins/fanctrlplus2/scripts/aux_sensors.sh" +source "$root/src/usr/local/emhttp/plugins/fanctrlplus2/scripts/disk_group_control.sh" + +failures=0 +expect_equal() { + local expected="$1" actual="$2" message="$3" + if [[ "$expected" == "$actual" ]]; then + return + fi + printf '%s\nExpected: %s\nActual: %s\n' "$message" "$expected" "$actual" >&2 + failures=$((failures + 1)) +} + +hour=3600 +gap=300 +acpi=/sys/class/hwmon/hwmon2/temp1_input +# One loop round at the given time: an Asustor NAS fan on its CPU sensor and +# the ACPI thermal zone, which this board fills with 27.8 °C. +round() { # time cpu acpi [disk] + local -a readings=("cpu|$2|1" "$acpi|$3|1") + [[ -n "${4:-}" ]] && readings+=("disk:0|$4|0") + fcp_track_frozen "$1" "$gap" "${readings[@]}" +} +# shellcheck disable=SC2154 +found() { printf '%s;' "${fcp_frozen_found[@]}"; } +# Rounds every 2 minutes from start to end, the CPU swinging between lo and hi. +run() { # start end lo hi acpi + local t cpu + for (( t = $1; t <= $2; t += 120 )); do + cpu=$(( $3 + (t / 120) % ($4 - $3 + 1) )) + round "$t" "$cpu" "$5" + done +} + +run 0 $(( 6 * hour - 120 )) 48 71 27 +expect_equal ';' "$(found)" "Under 6 hours unchanged is not yet a conclusion." +round $(( 6 * hour )) 55 27 +expect_equal "$acpi|27|0|$(( 6 * hour ))|cpu|48|71;" "$(found)" \ + "Unchanged for 6 hours while the CPU moved 23 degrees: the sensor is named with the CPU's range." + +round $(( 6 * hour + 120 )) 55 28 +expect_equal ';' "$(found)" "One degree of change ends the stretch." +run $(( 6 * hour + 240 )) $(( 13 * hour )) 50 59 28 +expect_equal ';' "$(found)" "Another source moving by less than 10 degrees is no evidence: a steady machine has steady sensors." + +fcp_frozen_run=() fcp_frozen_range=() +run 0 $(( 3 * hour )) 48 71 27 +run $(( 3 * hour + gap + 120 )) $(( 7 * hour )) 48 71 27 +expect_equal ';' "$(found)" "A gap longer than the interval allows (the loop was not running) starts the stretch over." + +fcp_frozen_run=() fcp_frozen_range=() +for (( t = 0; t <= 6 * hour; t += 120 )); do round "$t" $(( 40 + (t / 120) % 3 )) 27 $(( 30 + (t / hour) * 2 )); done +expect_equal "$acpi|27|0|$(( 6 * hour ))|disk:0|30|42;" "$(found)" \ + "A disk group that warmed by 12 degrees is evidence too, and the source that moved most is named." +fcp_frozen_run=() fcp_frozen_range=() +for (( t = 0; t <= 6 * hour; t += 120 )); do round "$t" $(( 48 + (t / 120) % 24 )) $(( 27 + (t / 120) % 2 )) 35; done +expect_equal ';' "$(found)" "A disk group is never judged itself: its reading is the hottest of several drives." + +fcp_frozen_run=() fcp_frozen_range=() +for (( t = 0; t <= 6 * hour; t += 120 )); do + fcp_track_frozen "$t" "$gap" "cpu||1" "$acpi|27|1" +done +expect_equal ';' "$(found)" "A source without a reading is no evidence." + +# The tracking survives a loop restart, and is published for the page. +fcp_frozen_run=() fcp_frozen_range=() +run 0 $(( 4 * hour )) 48 71 27 +fcp_frozen_save "$tmp/state" +fcp_frozen_run=() fcp_frozen_range=() +fcp_frozen_load "$tmp/state" +run $(( 4 * hour + 120 )) $(( 6 * hour )) 48 71 27 +expect_equal "$acpi|27|0|$(( 6 * hour ))|cpu|48|71;" "$(found)" "A restarted loop must keep the hours already seen." +fcp_frozen_publish "$tmp/frozen_Bay" +expect_equal "$acpi|27|0|$(( 6 * hour ))|cpu|48|71" "$(cat "$tmp/frozen_Bay")" "The conclusion is published for the settings page." +round $(( 6 * hour + 120 )) 55 28 +fcp_frozen_publish "$tmp/frozen_Bay" +expect_equal "" "$(cat "$tmp/frozen_Bay")" "A sensor that changed is no longer shown." +printf 'run|cpu|x|1|2\nrange|cpu>a|1\n' > "$tmp/bad_state" +fcp_frozen_load "$tmp/bad_state" +expect_equal 0 "$(( ${#fcp_frozen_run[@]} + ${#fcp_frozen_range[@]} ))" "A damaged state file is ignored." + +# ===== The warning ===== +printf '#!/bin/bash\nprintf "%%s\\n" "$@" >> "%s/calls"\n' "$tmp" > "$fcp_notify_bin" +chmod +x "$fcp_notify_bin" +cfg_file="$tmp/fan.cfg" +echo 'custom="Bay"' > "$cfg_file" +cpu_sensor=/sys/class/hwmon/hwmon4/temp1_input +conclusion="$acpi|27|0|$(( 6 * hour ))|cpu|48|71" +sent() { grep -c '^-s$' "$tmp/calls" 2>/dev/null; } + +fcp_notify_frozen Bay "$tmp/flag" "$conclusion" +fcp_notify_frozen Bay "$tmp/flag" "$conclusion" +expect_equal 1 "$(sent)" "A frozen sensor is warned about once per boot, by default." +expect_equal 1 "$(grep -cF "$acpi has read 27 °C for 6 hours while the CPU sensor $cpu_sensor varied 48–71 °C." "$tmp/calls")" \ + "The warning names the sensor, how long, and what moved meanwhile." +fcp_notify_frozen Bay "$tmp/flag" "cpu|27|0|$(( 6 * hour ))|disk:0|30|42" +expect_equal 2 "$(sent)" "Another sensor of the same fan gets its own warning." +: > "$tmp/calls" +echo 'frozen_notify="0"' > "$cfg_file" +fcp_notify_frozen Bay "$tmp/off_flag" "$conclusion" +expect_equal 0 "$(sent)" "With the Frozen Sensors switch off, nothing is sent." +echo 'notify="0"' > "$cfg_file" +fcp_notify_frozen Bay "$tmp/off_flag" "$conclusion" +expect_equal 1 "$(sent)" "The switch is its own: Problem Alerts off does not silence it." +: > "$tmp/calls" +good_notify=$fcp_notify_bin fcp_notify_bin=false +fcp_notify_frozen Bay "$tmp/retry_flag" "$conclusion" +fcp_notify_bin=$good_notify +fcp_notify_frozen Bay "$tmp/retry_flag" "$conclusion" +expect_equal 1 "$(sent)" "A warning that failed to send is tried again on the next round." +fcp_notify_frozen Bay "$tmp/missing/flag" "$conclusion" +expect_equal 1 "$(sent)" "Without a flag file, no warning is sent, so rounds cannot repeat it." + +if (( failures > 0 )); then + printf '%d frozen sensor assertion(s) failed.\n' "$failures" >&2 + exit 1 +fi +echo "frozen sensor tests passed" From d47450e6621e3a2daa71063c2ba3079fb71188da Mon Sep 17 00:00:00 2001 From: dev Date: Mon, 9 Nov 2026 11:42:55 +0200 Subject: [PATCH 2/3] fanctrlplus2: say what to do about a frozen sensor, with an example --- src/usr/local/emhttp/plugins/fanctrlplus2/fanctrlplus2.page | 2 +- .../local/emhttp/plugins/fanctrlplus2/include/Common.php | 2 +- .../plugins/fanctrlplus2/scripts/disk_group_control.sh | 2 +- tests/frozen_sensor_state_test.php | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/usr/local/emhttp/plugins/fanctrlplus2/fanctrlplus2.page b/src/usr/local/emhttp/plugins/fanctrlplus2/fanctrlplus2.page index af3bec6..dfff126 100644 --- a/src/usr/local/emhttp/plugins/fanctrlplus2/fanctrlplus2.page +++ b/src/usr/local/emhttp/plugins/fanctrlplus2/fanctrlplus2.page @@ -2076,7 +2076,7 @@ $(function() {

Note: The plugin only writes to syslog when the PWM value changes by more than 5 compared to the previous value — small changes are ignored to reduce log noise.

Problem Alerts are also enabled by default. Fan control keeps running either way; the alerts only send Unraid notifications. A fan gets one warning when, for at least 30 seconds, its PWM controller has disappeared, the BIOS or another program has taken it over, its controller reports a speed 10 or more percentage points away from the one set, or it reports 0 RPM while set above 40% after spinning earlier. A fan whose controller is missing when fan control starts, and a configured sensor without a reading for 60 seconds, also warn. Once the problem has stayed away for 30 seconds, a notice says so. Turn the alerts off for a fan whose controller raises false alarms, such as one with only a few speed steps.

When RPM has changed in the requested direction at least 30 seconds after a substantial speed change, a PWM mismatch warning includes that observation. It suggests that the fan may have responded despite the reported PWM; it does not prove which controller changed the fan.

-

Frozen Sensors: a CPU or auxiliary sensor whose reading has not changed by even 1 °C for 6 hours, while another source of the same fan moved by 10 °C or more, may report a fixed placeholder rather than a measurement (some boards fill ACPI thermal zones with 27.8 °C). The settings page always shows this beside the sensor; this switch, enabled by default, also sends one Unraid warning per sensor per boot. Fan control is unchanged either way.

+

Frozen Sensors: a CPU or auxiliary sensor whose reading has not changed by even 1 °C for 6 hours, while another source of the same fan moved by 10 °C or more, may report a fixed placeholder rather than a measurement (some boards fill ACPI thermal zones with 27.8 °C). The settings page always shows this beside the sensor; this switch, enabled by default, also sends one Unraid warning per sensor per boot. Fan control is unchanged either way. If it shows, pick another sensor for that fan, ex. the CPU package or a board System sensor; leave the switch on unless the sensor is known to be fixed and you keep it on purpose.

diff --git a/src/usr/local/emhttp/plugins/fanctrlplus2/include/Common.php b/src/usr/local/emhttp/plugins/fanctrlplus2/include/Common.php index b907be5..ed80c55 100644 --- a/src/usr/local/emhttp/plugins/fanctrlplus2/include/Common.php +++ b/src/usr/local/emhttp/plugins/fanctrlplus2/include/Common.php @@ -92,7 +92,7 @@ function fcp_frozen_sensors(string $file, int $stale, ?int $now = null): array { // page names the source that moved. function fcp_frozen_text(array $frozen, string $other): string { $hours = intdiv($frozen['last'] - $frozen['since'], 3600); - return "Unchanged at {$frozen['value']} °C for $hours h while $other varied {$frozen['lo']}–{$frozen['hi']} °C: may be a fixed placeholder."; + return "Unchanged at {$frozen['value']} °C for $hours h while $other varied {$frozen['lo']}–{$frozen['hi']} °C: may be a fixed placeholder. Pick another sensor for this fan, ex. the CPU package or a board System sensor."; } // ============================= diff --git a/src/usr/local/emhttp/plugins/fanctrlplus2/scripts/disk_group_control.sh b/src/usr/local/emhttp/plugins/fanctrlplus2/scripts/disk_group_control.sh index 9819a8b..f4eb2dd 100644 --- a/src/usr/local/emhttp/plugins/fanctrlplus2/scripts/disk_group_control.sh +++ b/src/usr/local/emhttp/plugins/fanctrlplus2/scripts/disk_group_control.sh @@ -698,7 +698,7 @@ fcp_notify_frozen() { touch "$flag" 2>/dev/null || return 0 hours=$(( (last - since) / 3600 )) fcp_notify -i warning -s "Fan $name has a temperature sensor that does not change" \ - -d "$(fcp_frozen_label "$src") has read $value °C for $hours hours while $(fcp_frozen_label "$other") varied $lo–$hi °C. It may report a fixed value rather than a measurement. Fan control is unchanged." && + -d "$(fcp_frozen_label "$src") has read $value °C for $hours hours while $(fcp_frozen_label "$other") varied $lo–$hi °C. It may report a fixed value rather than a measurement. Fan control is unchanged; pick another sensor for this fan, ex. the CPU package or a board System sensor." && printf '%s\n' "$src" >> "$flag" done } diff --git a/tests/frozen_sensor_state_test.php b/tests/frozen_sensor_state_test.php index 5be10d0..d7662cf 100644 --- a/tests/frozen_sensor_state_test.php +++ b/tests/frozen_sensor_state_test.php @@ -26,7 +26,7 @@ $check(array_keys($frozen) === [$acpi, 'cpu'], 'Only well-formed conclusions the loop renewed recently are shown, got '.json_encode(array_keys($frozen))); $check(($frozen[$acpi]['lo'] ?? null) === 48 && ($frozen[$acpi]['hi'] ?? null) === 71 && ($frozen[$acpi]['other'] ?? '') === 'cpu', 'A conclusion keeps the source that moved and its range.'); $check(fcp_frozen_sensors("$root/none", 540, $now) === [], 'A fan without a published file has no conclusion.'); -$check(fcp_frozen_text($frozen[$acpi], 'CPU') === 'Unchanged at 27 °C for 6 h while CPU varied 48–71 °C: may be a fixed placeholder.', +$check(fcp_frozen_text($frozen[$acpi], 'CPU') === 'Unchanged at 27 °C for 6 h while CPU varied 48–71 °C: may be a fixed placeholder. Pick another sensor for this fan, ex. the CPU package or a board System sensor.', 'The state says what was seen, for how long, and against what.'); $cfg = ['file' => 'fanctrlplus2_Bay.cfg', 'custom' => 'Bay', 'cpu_enable' => '1', 'aux_enable' => '1', @@ -35,9 +35,9 @@ $cpu = ['/sys/class/hwmon/hwmon4/temp1_input' => 'coretemp - Package id 0 (55°C)']; $aux = ['acpitz' => [['path' => $acpi, 'label' => 'acpitz - temp1 (27.8°C)']], 'Custom Sensors' => [['path' => 'custom:ambient', 'label' => 'ambient (24°C)']]]; $block = render_fan_block($cfg, 0, [], [], [], $cpu, $aux, $frozen); -$check(str_contains($block, 'Unchanged at 41 °C for 6 h while Disk: NVMe varied 30–42 °C: may be a fixed placeholder.'), +$check(str_contains($block, 'Unchanged at 41 °C for 6 h while Disk: NVMe varied 30–42 °C: may be a fixed placeholder. Pick another sensor for this fan, ex. the CPU package or a board System sensor.'), 'The CPU sensor shows its state, naming the disk group that moved.'); -$check(str_contains($block, 'acpitz - temp1: Unchanged at 27 °C for 6 h while CPU varied 48–71 °C: may be a fixed placeholder.'), +$check(str_contains($block, 'acpitz - temp1: Unchanged at 27 °C for 6 h while CPU varied 48–71 °C: may be a fixed placeholder. Pick another sensor for this fan, ex. the CPU package or a board System sensor.'), 'An aux sensor shows its state, named as the list names it.'); $check(substr_count($block, 'fcp-sensor-state') === 2, 'A sensor without a conclusion shows nothing.'); $check(!str_contains(render_fan_block($cfg, 0, [], [], [], $cpu, $aux, []), 'fcp-sensor-state'), 'No conclusions, no state.'); From 3064618b0b1abd92f182bbb24f54c18a05a46b3c Mon Sep 17 00:00:00 2001 From: dev Date: Wed, 11 Nov 2026 20:35:09 +0200 Subject: [PATCH 3/3] fanctrlplus2: frozen sensors: forget the tracking when the fan's sensors change, warn per CPU sensor The saved tracking now carries a checksum of the CPU sensor, aux sensor and disks the fan reads, and is dropped on load when it differs, so a new sensor cannot continue the old one's unchanged stretch. The once-per-boot warning flag for the CPU names the sensor, so choosing another CPU sensor can warn again. Tests cover both, plus a comparison source that stops reporting. --- .../scripts/disk_group_control.sh | 26 +++++++++++++++---- .../fanctrlplus2/scripts/fanctrlplus2_loop.sh | 9 +++++-- tests/frozen_sensor_test.sh | 22 ++++++++++++++-- 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/src/usr/local/emhttp/plugins/fanctrlplus2/scripts/disk_group_control.sh b/src/usr/local/emhttp/plugins/fanctrlplus2/scripts/disk_group_control.sh index f4eb2dd..62b5578 100644 --- a/src/usr/local/emhttp/plugins/fanctrlplus2/scripts/disk_group_control.sh +++ b/src/usr/local/emhttp/plugins/fanctrlplus2/scripts/disk_group_control.sh @@ -643,20 +643,32 @@ fcp_track_frozen() { } # The tracking survives a loop restart (applying settings restarts every -# loop) in a RAM file: "run|SOURCE|VALUE|SINCE|LAST" and "range|SOURCE>OTHER|LO|HI". +# loop) in a RAM file: "id|SUM", "run|SOURCE|VALUE|SINCE|LAST" and +# "range|SOURCE>OTHER|LO|HI". The id stands for which sensors and disks the +# fan is set to read (a second argument, any text): a stretch recorded for +# other ones says nothing about these, so it is not carried over. +fcp_frozen_identity() { + local sum + sum=$(printf '%s' "$1" | cksum) + printf '%s' "${sum%% *}" +} + fcp_frozen_save() { local file="$1" key tmp="${1}.tmp.$$" { + printf 'id|%s\n' "$(fcp_frozen_identity "${2:-}")" for key in "${!fcp_frozen_run[@]}"; do printf 'run|%s|%s\n' "$key" "${fcp_frozen_run[$key]}"; done for key in "${!fcp_frozen_range[@]}"; do printf 'range|%s|%s\n' "$key" "${fcp_frozen_range[$key]}"; done } > "$tmp" 2>/dev/null && mv -f "$tmp" "$file" 2>/dev/null } fcp_frozen_load() { - local file="$1" kind key rest + local file="$1" kind key rest id fcp_frozen_run=() fcp_frozen_range=() [[ -f "$file" ]] || return 0 + id=$(fcp_frozen_identity "${2:-}") + grep -qxF -- "id|$id" "$file" 2>/dev/null || return 0 while IFS='|' read -r kind key rest; do case "$kind" in run) [[ "$rest" =~ ^[0-9]+\|[0-9]+\|[0-9]+$ ]] && fcp_frozen_run[$key]=$rest ;; @@ -689,16 +701,20 @@ fcp_frozen_alerts_enabled() { # sensors already warned about; a failed notification leaves a sensor out, # so the next round tries again. fcp_notify_frozen() { - local name="$1" flag="$2" found src value since last other lo hi hours + local name="$1" flag="$2" found src value since last other lo hi hours key shift 2 for found in "$@"; do IFS='|' read -r src value since last other lo hi <<< "$found" - grep -qxF -- "$src" "$flag" 2>/dev/null && continue + # The flag names the physical sensor: "cpu" alone would stay flagged + # after the fan is pointed at another CPU sensor. + key=$src + [[ "$src" == cpu ]] && key="cpu:${cpu_sensor:-}" + grep -qxF -- "$key" "$flag" 2>/dev/null && continue fcp_frozen_alerts_enabled || return 0 touch "$flag" 2>/dev/null || return 0 hours=$(( (last - since) / 3600 )) fcp_notify -i warning -s "Fan $name has a temperature sensor that does not change" \ -d "$(fcp_frozen_label "$src") has read $value °C for $hours hours while $(fcp_frozen_label "$other") varied $lo–$hi °C. It may report a fixed value rather than a measurement. Fan control is unchanged; pick another sensor for this fan, ex. the CPU package or a board System sensor." && - printf '%s\n' "$src" >> "$flag" + printf '%s\n' "$key" >> "$flag" done } diff --git a/src/usr/local/emhttp/plugins/fanctrlplus2/scripts/fanctrlplus2_loop.sh b/src/usr/local/emhttp/plugins/fanctrlplus2/scripts/fanctrlplus2_loop.sh index a8df13a..e3ea84c 100644 --- a/src/usr/local/emhttp/plugins/fanctrlplus2/scripts/fanctrlplus2_loop.sh +++ b/src/usr/local/emhttp/plugins/fanctrlplus2/scripts/fanctrlplus2_loop.sh @@ -70,8 +70,13 @@ prev_hist_src=$(tail -n 1 "$hist_file" 2>/dev/null | cut -d'|' -f2) # Sensors that have read the same for hours (fcp_track_frozen), carried over # from before a restart. +# The state is dropped when the fan is set to other sensors or disks. frozen_state="/var/tmp/${plugin}/frozen_state_${custom}" -fcp_frozen_load "$frozen_state" +frozen_identity="${cpu_sensor:-}|${aux_sensor:-}|${disks:-}" +for curve_key in ${!disk_group_@}; do + [[ "$curve_key" == *_disks ]] && frozen_identity+="|$curve_key=${!curve_key}" +done +fcp_frozen_load "$frozen_state" "$frozen_identity" # Whether the last controller write, and the last curve-state snapshot, failed. # Each is logged once per stretch, not every round. @@ -279,7 +284,7 @@ while true; do done printf -v frozen_now '%(%s)T' -1 fcp_track_frozen "$frozen_now" $(( 2 * $(interval_seconds) + 60 )) "${frozen_readings[@]}" - fcp_frozen_save "$frozen_state" + fcp_frozen_save "$frozen_state" "$frozen_identity" fcp_frozen_publish "/var/tmp/${plugin}/frozen_${custom}" if (( ${#fcp_frozen_found[@]} )); then fcp_notify_frozen "$custom" "/var/tmp/${plugin}/sensor_frozen_${custom}" "${fcp_frozen_found[@]}" diff --git a/tests/frozen_sensor_test.sh b/tests/frozen_sensor_test.sh index 86018b8..d625972 100644 --- a/tests/frozen_sensor_test.sh +++ b/tests/frozen_sensor_test.sh @@ -76,13 +76,18 @@ expect_equal ';' "$(found)" "A source without a reading is no evidence." # The tracking survives a loop restart, and is published for the page. fcp_frozen_run=() fcp_frozen_range=() run 0 $(( 4 * hour )) 48 71 27 -fcp_frozen_save "$tmp/state" +fcp_frozen_save "$tmp/state" "cpu1|aux" fcp_frozen_run=() fcp_frozen_range=() -fcp_frozen_load "$tmp/state" +fcp_frozen_load "$tmp/state" "cpu1|aux" run $(( 4 * hour + 120 )) $(( 6 * hour )) 48 71 27 expect_equal "$acpi|27|0|$(( 6 * hour ))|cpu|48|71;" "$(found)" "A restarted loop must keep the hours already seen." fcp_frozen_publish "$tmp/frozen_Bay" expect_equal "$acpi|27|0|$(( 6 * hour ))|cpu|48|71" "$(cat "$tmp/frozen_Bay")" "The conclusion is published for the settings page." +fcp_frozen_load "$tmp/state" "cpu2|aux" +expect_equal 0 "$(( ${#fcp_frozen_run[@]} + ${#fcp_frozen_range[@]} ))" "Tracking recorded for other sensors is not carried over." +fcp_frozen_load "$tmp/state" +expect_equal 0 "$(( ${#fcp_frozen_run[@]} + ${#fcp_frozen_range[@]} ))" "Tracking without a matching identity is not carried over." +fcp_frozen_load "$tmp/state" "cpu1|aux" round $(( 6 * hour + 120 )) 55 28 fcp_frozen_publish "$tmp/frozen_Bay" expect_equal "" "$(cat "$tmp/frozen_Bay")" "A sensor that changed is no longer shown." @@ -90,6 +95,13 @@ printf 'run|cpu|x|1|2\nrange|cpu>a|1\n' > "$tmp/bad_state" fcp_frozen_load "$tmp/bad_state" expect_equal 0 "$(( ${#fcp_frozen_run[@]} + ${#fcp_frozen_range[@]} ))" "A damaged state file is ignored." +# A comparison source that stopped reporting: the stretch it moved in is still +# what it did, so the conclusion stands and names the readings it had. +fcp_frozen_run=() fcp_frozen_range=() +run 0 $(( hour )) 48 71 27 +for (( t = hour + 120; t <= 6 * hour; t += 120 )); do fcp_track_frozen "$t" "$gap" "$acpi|27|1"; done +expect_equal "$acpi|27|0|$(( 6 * hour ))|cpu|48|71;" "$(found)" "A comparison source that went quiet keeps the movement it showed." + # ===== The warning ===== printf '#!/bin/bash\nprintf "%%s\\n" "$@" >> "%s/calls"\n' "$tmp" > "$fcp_notify_bin" chmod +x "$fcp_notify_bin" @@ -106,6 +118,12 @@ expect_equal 1 "$(grep -cF "$acpi has read 27 °C for 6 hours while the CPU sens "The warning names the sensor, how long, and what moved meanwhile." fcp_notify_frozen Bay "$tmp/flag" "cpu|27|0|$(( 6 * hour ))|disk:0|30|42" expect_equal 2 "$(sent)" "Another sensor of the same fan gets its own warning." +cpu_sensor=/sys/class/hwmon/hwmon5/temp1_input +fcp_notify_frozen Bay "$tmp/flag" "cpu|27|0|$(( 6 * hour ))|disk:0|30|42" +expect_equal 3 "$(sent)" "A CPU sensor chosen later is warned about on its own." +fcp_notify_frozen Bay "$tmp/flag" "cpu|27|0|$(( 6 * hour ))|disk:0|30|42" +expect_equal 3 "$(sent)" "The same CPU sensor is still warned about only once." +cpu_sensor=/sys/class/hwmon/hwmon4/temp1_input : > "$tmp/calls" echo 'frozen_notify="0"' > "$cfg_file" fcp_notify_frozen Bay "$tmp/off_flag" "$conclusion"