fix monitor disk used space underreported for spun-down disks

Unraid API returns fsUsed=0 when a disk's filesystem is unmounted (spun
down). disks.ini keeps the last-known value in KB even after spindown —
use it as fallback when isSpinning=false and fsUsed=0. Also remove the
mounted-only guard in the ini fallback path (vv_disk_entry) for the same
reason. Stale comments in user_script_plug-in.sh and partnership_manager.sh
also cleaned up.
This commit is contained in:
Gmer4Lfe
2026-06-27 23:08:51 -04:00
parent 75f2a4e3fd
commit b314aa4aff
4 changed files with 30 additions and 9 deletions
+10 -2
View File
@@ -111,7 +111,9 @@ function _vv_api_disk_role(string $type): string {
// Build a normalised disk entry from API data, matching the shape vv_disk_entry() produces.
// $role may be overridden; if empty it is derived from the disk's type field.
function vv_api_disk_entry(array $d, string $role = ''): ?array {
// $ini_used_kb: last-known fsUsed in KB from disks.ini — used when the disk is
// spun down and the API returns fsUsed=0 because the filesystem is unmounted.
function vv_api_disk_entry(array $d, string $role = '', int $ini_used_kb = 0): ?array {
if (!$role) $role = _vv_api_disk_role((string)($d['type'] ?? 'DATA'));
if ($role === 'parity') {
@@ -127,7 +129,13 @@ function vv_api_disk_entry(array $d, string $role = ''): ?array {
if ($sizeRaw <= 0) return null;
$usedRaw = (float)($d['fsUsed'] ?? 0);
$sizeGb = _vv_api_bytes_to_gb($sizeRaw);
$usedGb = _vv_api_bytes_to_gb($usedRaw);
if ($usedRaw > 0.0) {
$usedGb = _vv_api_bytes_to_gb($usedRaw);
} elseif (!($d['isSpinning'] ?? true) && $ini_used_kb > 0) {
$usedGb = round($ini_used_kb / 1048576, 1);
} else {
$usedGb = 0.0;
}
$pct = $sizeGb > 0 ? round($usedGb / $sizeGb * 100, 1) : null;
}