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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user