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:
@@ -1281,7 +1281,7 @@ if [[ "$MODE" == "onboard" ]]; then
|
|||||||
warn "DRY RUN — would write ACTIVE state and push to remote"
|
warn "DRY RUN — would write ACTIVE state and push to remote"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Emby admin provisioning — runs after container deployment (deploy step not yet built)
|
# Emby admin provisioning — runs after container deployment
|
||||||
provision_emby_admin "$MIRROR_IP"
|
provision_emby_admin "$MIRROR_IP"
|
||||||
|
|
||||||
# Summary
|
# Summary
|
||||||
|
|||||||
@@ -345,7 +345,7 @@ function vv_disk_entry(array $d, string $key, string $role = 'data'): ?array {
|
|||||||
$mounted = ($d['fsStatus'] ?? '') === 'Mounted';
|
$mounted = ($d['fsStatus'] ?? '') === 'Mounted';
|
||||||
// Parity has no filesystem — use raw size only
|
// Parity has no filesystem — use raw size only
|
||||||
$size_kb = (int)($isParity ? ($d['size'] ?? 0) : ($mounted ? ($d['fsSize'] ?? 0) : ($d['size'] ?? 0)));
|
$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;
|
if ($size_kb <= 0) return null;
|
||||||
$tempRaw = trim($d['temp'] ?? '');
|
$tempRaw = trim($d['temp'] ?? '');
|
||||||
return [
|
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 {
|
function vv_storage_pools(): array {
|
||||||
// ── API path ──────────────────────────────────────────────────────────────
|
// ── API path ──────────────────────────────────────────────────────────────
|
||||||
$api = vv_api_data();
|
$api = vv_api_data();
|
||||||
if ($api && isset($api['array']['caches'])) {
|
if ($api && isset($api['array']['caches'])) {
|
||||||
|
$ini_used = _vv_ini_used_kb();
|
||||||
$out = [];
|
$out = [];
|
||||||
foreach ($api['array']['caches'] as $d) {
|
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 ($entry) $out[] = $entry;
|
||||||
}
|
}
|
||||||
if (!empty($out)) {
|
if (!empty($out)) {
|
||||||
@@ -505,6 +519,7 @@ function vv_array_disks(): array {
|
|||||||
// ── API path ──────────────────────────────────────────────────────────────
|
// ── API path ──────────────────────────────────────────────────────────────
|
||||||
$api = vv_api_data();
|
$api = vv_api_data();
|
||||||
if ($api && (isset($api['array']['parities']) || isset($api['array']['disks']))) {
|
if ($api && (isset($api['array']['parities']) || isset($api['array']['disks']))) {
|
||||||
|
$ini_used = _vv_ini_used_kb();
|
||||||
$parity = [];
|
$parity = [];
|
||||||
$data = [];
|
$data = [];
|
||||||
foreach ($api['array']['parities'] ?? [] as $d) {
|
foreach ($api['array']['parities'] ?? [] as $d) {
|
||||||
@@ -512,7 +527,7 @@ function vv_array_disks(): array {
|
|||||||
if ($entry) $parity[] = $entry;
|
if ($entry) $parity[] = $entry;
|
||||||
}
|
}
|
||||||
foreach ($api['array']['disks'] ?? [] as $d) {
|
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 ($entry) $data[] = $entry;
|
||||||
}
|
}
|
||||||
if (!empty($parity) || !empty($data)) {
|
if (!empty($parity) || !empty($data)) {
|
||||||
|
|||||||
@@ -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.
|
// 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.
|
// $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) $role = _vv_api_disk_role((string)($d['type'] ?? 'DATA'));
|
||||||
|
|
||||||
if ($role === 'parity') {
|
if ($role === 'parity') {
|
||||||
@@ -127,7 +129,13 @@ function vv_api_disk_entry(array $d, string $role = ''): ?array {
|
|||||||
if ($sizeRaw <= 0) return null;
|
if ($sizeRaw <= 0) return null;
|
||||||
$usedRaw = (float)($d['fsUsed'] ?? 0);
|
$usedRaw = (float)($d['fsUsed'] ?? 0);
|
||||||
$sizeGb = _vv_api_bytes_to_gb($sizeRaw);
|
$sizeGb = _vv_api_bytes_to_gb($sizeRaw);
|
||||||
|
if ($usedRaw > 0.0) {
|
||||||
$usedGb = _vv_api_bytes_to_gb($usedRaw);
|
$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;
|
$pct = $sizeGb > 0 ? round($usedGb / $sizeGb * 100, 1) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -347,9 +347,7 @@
|
|||||||
# A reboot between the 14th and 15th will defer maintenance — which is intentional;
|
# A reboot between the 14th and 15th will defer maintenance — which is intentional;
|
||||||
# heavy tasks (ZFS scrub, SMART long test) should not run on a freshly rebooted system.
|
# heavy tasks (ZFS scrub, SMART long test) should not run on a freshly rebooted system.
|
||||||
#
|
#
|
||||||
# Configure via master.conf MONTHLY_MAINTENANCE_SCRIPTS. Scripts planned but not yet built:
|
# Configure via master.conf MONTHLY_MAINTENANCE_SCRIPTS — see Tools/zfs_pool_scrub.sh and Tools/smart_long_test.sh.
|
||||||
# zfs_pool_scrub.sh ZFS pool integrity scrub (Tools/)
|
|
||||||
# smart_long_test.sh SMART extended drive health test (Tools/)
|
|
||||||
#
|
#
|
||||||
# bash /boot/config/plugins/varaverk/Orchestrators/monthly_maintenance.sh
|
# bash /boot/config/plugins/varaverk/Orchestrators/monthly_maintenance.sh
|
||||||
# bash /boot/config/plugins/varaverk/Orchestrators/monthly_maintenance.sh --dry-run
|
# bash /boot/config/plugins/varaverk/Orchestrators/monthly_maintenance.sh --dry-run
|
||||||
|
|||||||
Reference in New Issue
Block a user