Arrs: remote host cards via SSH cache, vv_arrs_local_node(), 2h refresh schedule

This commit is contained in:
Gmer4Lfe
2026-06-03 18:16:56 -04:00
parent 6c0164713b
commit 2223cf80f7
4 changed files with 245 additions and 23 deletions
+47 -18
View File
@@ -240,32 +240,61 @@ function vv_arr_recovery_stats(): array {
return $out;
}
// ── Local node only — called via SSH by remote_arr_cache_writer.sh on remote hosts ───────────
function vv_arrs_local_node(): array {
$host = vv_detect_host();
$names = vv_arr_node_names();
$arrs = [];
foreach (vv_discover_arrs() as $node) {
if ($node['host'] !== $host) continue;
foreach ($node['arrs'] as $arr) {
$entry = ['type' => $arr['type'], 'root' => $arr['root']];
$entry = array_merge($entry, vv_fetch_arr_live($arr));
$entry['cleanup'] = vv_arr_cleanup_stats($arr['type']);
$entry['discovery'] = vv_arr_discovery_stats($arr['type']);
$arrs[] = $entry;
}
break;
}
return [
'host' => $host,
'name' => $names[$host] ?? strtoupper($host),
'local' => true,
'arrs' => $arrs,
];
}
// ── Entry point ───────────────────────────────────────────────────────────────
function vv_arrs_all(): array {
$currentHost = vv_detect_host();
$names = vv_arr_node_names();
$allNodes = vv_discover_arrs();
$result = [];
foreach ($allNodes as $node) {
$h = $node['host'];
$isLocal = ($h === $currentHost || $currentHost === 'unknown');
$nodeOut = ['host' => $h, 'name' => $names[$h] ?? strtoupper($h), 'local' => $isLocal, 'arrs' => []];
// Local node — full live data
$result = [vv_arrs_local_node()];
foreach ($node['arrs'] as $arr) {
$entry = ['type' => $arr['type'], 'root' => $arr['root']];
if ($isLocal) {
$entry = array_merge($entry, vv_fetch_arr_live($arr));
$entry['cleanup'] = vv_arr_cleanup_stats($arr['type']);
$entry['discovery'] = vv_arr_discovery_stats($arr['type']);
} else {
$entry['online'] = false;
$entry['remote'] = true;
}
$nodeOut['arrs'][] = $entry;
// Remote nodes — read from file cache written by remote_arr_cache_writer.sh
foreach (array_keys($names) as $h) {
if ($h === $currentHost) continue;
$cacheFile = VV_CACHE_DIR . '/arrs_remote_' . $h . '.json';
if (file_exists($cacheFile)) {
$node = json_decode(file_get_contents($cacheFile), true) ?: [];
$node['cached'] = true;
$node['cache_age'] = time() - (int)filemtime($cacheFile);
$result[] = $node;
} else {
$result[] = [
'host' => $h,
'name' => $names[$h],
'local' => false,
'cached' => false,
'cache_miss' => true,
'arrs' => [],
];
}
$result[] = $nodeOut;
}
$vars = vv_conf_vars();