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
+18 -3
View File
@@ -345,7 +345,7 @@ function vv_disk_entry(array $d, string $key, string $role = 'data'): ?array {
$mounted = ($d['fsStatus'] ?? '') === 'Mounted';
// Parity has no filesystem — use raw size only
$size_kb = (int)($isParity ? ($d['size'] ?? 0) : ($mounted ? ($d['fsSize'] ?? 0) : ($d['size'] ?? 0)));
$used_kb = (int)($isParity ? 0 : ($mounted ? ($d['fsUsed'] ?? 0) : 0));
$used_kb = (int)($isParity ? 0 : ($d['fsUsed'] ?? 0));
if ($size_kb <= 0) return null;
$tempRaw = trim($d['temp'] ?? '');
return [
@@ -472,13 +472,27 @@ function vv_parity_status(): array {
];
}
// Returns a map of disk name → fsUsed in KB from disks.ini.
// Unraid keeps this updated even after spindown, so it's the authoritative source
// for used space when the API reports 0 because the filesystem is unmounted.
function _vv_ini_used_kb(): array {
$ini = @parse_ini_file('/var/local/emhttp/disks.ini', true) ?: [];
$out = [];
foreach ($ini as $key => $d) {
$name = $d['name'] ?? $key;
$out[$name] = (int)($d['fsUsed'] ?? 0);
}
return $out;
}
function vv_storage_pools(): array {
// ── API path ──────────────────────────────────────────────────────────────
$api = vv_api_data();
if ($api && isset($api['array']['caches'])) {
$ini_used = _vv_ini_used_kb();
$out = [];
foreach ($api['array']['caches'] as $d) {
$entry = vv_api_disk_entry($d, 'data');
$entry = vv_api_disk_entry($d, 'data', $ini_used[$d['name'] ?? ''] ?? 0);
if ($entry) $out[] = $entry;
}
if (!empty($out)) {
@@ -505,6 +519,7 @@ function vv_array_disks(): array {
// ── API path ──────────────────────────────────────────────────────────────
$api = vv_api_data();
if ($api && (isset($api['array']['parities']) || isset($api['array']['disks']))) {
$ini_used = _vv_ini_used_kb();
$parity = [];
$data = [];
foreach ($api['array']['parities'] ?? [] as $d) {
@@ -512,7 +527,7 @@ function vv_array_disks(): array {
if ($entry) $parity[] = $entry;
}
foreach ($api['array']['disks'] ?? [] as $d) {
$entry = vv_api_disk_entry($d, 'data');
$entry = vv_api_disk_entry($d, 'data', $ini_used[$d['name'] ?? ''] ?? 0);
if ($entry) $data[] = $entry;
}
if (!empty($parity) || !empty($data)) {
+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;
}