Remote cache: extend to monitor stats; vv_local_host_stats(), 2h bg refresh covers monitor+arrs pages

This commit is contained in:
Gmer4Lfe
2026-06-03 18:20:55 -04:00
parent 2223cf80f7
commit a55a3afad5
3 changed files with 91 additions and 10 deletions
+28 -10
View File
@@ -81,38 +81,56 @@ for host_var in HOST1 HOST2 HOST3 HOST4 HOST5 HOST6 HOST7 HOST8; do
fi
log " $host_var: resolved $hostname$REMOTE_IP"
# SSH and call vv_arrs_local_node() on the remote
# Single SSH connection — fetch arrs + monitor stats together
RESULT=$(ssh -i "$SSH_KEY" \
-o ConnectTimeout=10 \
-o StrictHostKeyChecking=no \
-o BatchMode=yes \
"root@${REMOTE_IP}" \
"php -r \"require_once '/usr/local/emhttp/plugins/varaverk/include/arrs.php'; echo json_encode(vv_arrs_local_node());\"" \
2>/dev/null)
"php -r \"
require_once '/usr/local/emhttp/plugins/varaverk/include/arrs.php';
require_once '/usr/local/emhttp/plugins/varaverk/include/unraid_api.php';
echo json_encode([
'arrs' => vv_arrs_local_node(),
'monitor' => vv_local_host_stats(),
]);
\"" 2>/dev/null)
if [[ -z "$RESULT" ]]; then
warn " $host_var: empty response from SSH — skipping"
warn " $host_var: empty SSH response — skipping"
(( FETCH_FAIL++ ))
continue
fi
# Validate JSON
# Validate combined JSON
if ! echo "$RESULT" | php -r "
\$d = json_decode(file_get_contents('php://stdin'), true);
exit(!is_array(\$d) || !isset(\$d['arrs']) ? 1 : 0);
exit(!is_array(\$d) || !isset(\$d['arrs'], \$d['monitor']) ? 1 : 0);
" 2>/dev/null; then
warn " $host_var: invalid or unexpected JSON — skipping"
warn " $host_var: invalid JSON — skipping"
log " Response: ${RESULT:0:200}"
(( FETCH_FAIL++ ))
continue
fi
echo "$RESULT" > "$cache_file"
# Save arr cache
echo "$RESULT" | php -r "
\$d = json_decode(file_get_contents('php://stdin'), true);
file_put_contents('$cache_file', json_encode(\$d['arrs']));
" 2>/dev/null
# Save monitor cache
MONITOR_CACHE="/tmp/vv_cache/monitor_remote_${host_id}.json"
echo "$RESULT" | php -r "
\$d = json_decode(file_get_contents('php://stdin'), true);
file_put_contents('$MONITOR_CACHE', json_encode(\$d['monitor']));
" 2>/dev/null
CACHED_TYPES=$(echo "$RESULT" | php -r "
\$d = json_decode(file_get_contents('php://stdin'), true);
echo implode(', ', array_column(\$d['arrs'] ?? [], 'type'));
echo implode(', ', array_column(\$d['arrs']['arrs'] ?? [], 'type'));
" 2>/dev/null)
echo " $host_var: cached ✅ — ${CACHED_TYPES:-no arrs}"
echo " $host_var: arrs [${CACHED_TYPES:-none}] + monitor stats cached ✅"
(( FETCH_OK++ ))
done