Read the CPU temperature instead of the alarm threshold beside it

lm-sensors prints high= and crit= on the same line as the reading, so scraping
the line for its largest number reported a flat 100C on Intel while the shell's
last-field parse got a bare ")" and never fired at all. One parse in the
adapter now, preferring Tdie over Tctl since Tctl carries a +27C offset.
This commit is contained in:
Gmer4Lfe
2026-08-21 08:17:36 -04:00
parent a07019e3aa
commit 4a29e7bc99
4 changed files with 81 additions and 9 deletions
+35
View File
@@ -507,6 +507,41 @@ function vv_ups_stats(): array {
];
}
// CPU temperature in °C, or null if no sensor answers.
//
// Mirror of platform_get_cpu_temp() in Plugin/unraid/adapter.sh — the two must agree, because the
// Monitor card and the stability watchdog display and act on the same number, and for months they
// did not. The PHP side scraped every decimal off the sensor line and took the largest, which on
// any board printing "(high = +80.0 C, crit = +100.0 C)" is the critical threshold: HOST2 reported
// a flat 100°C while sitting at 63. The shell side took the line's last field, which on that same
// board is the literal ")", so its check silently never fired.
//
// Both defects came from parsing a line that carries three temperatures when only one of them is a
// reading. The parenthetical is stripped before any digit is read.
//
// Tdie before Tctl for the AMD reason: Tctl carries a fixed offset (+27°C on Threadripper) and is
// a control value, not a measurement — it is why HOST1 read 70 while the die was at 43.
function vv_cpu_temp(): ?int {
$out = shell_exec('sensors 2>/dev/null') ?: '';
if (trim($out) === '') return null;
$out = preg_replace('/\(.*$/m', '', $out); // drop "(high = ..., crit = ...)"
foreach (['Tdie', 'Package id 0', 'CPU Temp', 'Core '] as $label) {
$best = null;
foreach (explode("\n", $out) as $line) {
if (stripos(ltrim($line), $label) !== 0) continue;
if (!preg_match('/([+-]?\d+\.\d+)/', $line, $m)) continue;
$v = (float)$m[1];
// Max within a label: a multi-die part publishes one line per die, and the hottest is
// the one worth acting on.
if ($best === null || $v > $best) $best = $v;
}
if ($best !== null) return (int)round($best);
}
return null;
}
function vv_parity_status(): array {
$var = [];
foreach (@file('/var/local/emhttp/var.ini') ?: [] as $line) {
+1 -3
View File
@@ -275,9 +275,7 @@ function vv_watchdog_summary(): array {
$loadRaw = @file_get_contents('/proc/loadavg') ?: '0';
$load1 = (float)explode(' ', trim($loadRaw))[0];
$cpuTemp = null;
$sensorsOut = shell_exec("sensors 2>/dev/null | grep -E 'Core 0|Package id 0|Tdie|Tctl|CPU Temp' | grep -oE '[0-9]+\\.[0-9]+' | sort -n | tail -1") ?: '';
if ($sensorsOut && is_numeric(trim($sensorsOut))) $cpuTemp = (int)round((float)trim($sensorsOut));
$cpuTemp = vv_cpu_temp();
$zombies = (int)trim(shell_exec("ps -eo stat 2>/dev/null | grep -c '^Z'") ?: '0');