diff --git a/Plugin/unraid/api/monitor.php b/Plugin/unraid/api/monitor.php index 30fc135..abb8f95 100644 --- a/Plugin/unraid/api/monitor.php +++ b/Plugin/unraid/api/monitor.php @@ -28,6 +28,7 @@ echo json_encode([ 'disk_io' => vv_disk_io_rates(), 'watchdog' => vv_watchdog_summary(), 'scripts' => vv_scripts_status(), + 'rsync' => vv_rsync_status(), 'thresholds' => vv_disk_thresholds(), 'vms' => vv_get_vms(), 'docker_folders' => vv_get_docker_folders(), diff --git a/Plugin/unraid/include/monitor.php b/Plugin/unraid/include/monitor.php index a7c9079..d00e5d1 100644 --- a/Plugin/unraid/include/monitor.php +++ b/Plugin/unraid/include/monitor.php @@ -319,3 +319,58 @@ function vv_scripts_status(): array { 'error_count' => count(array_filter($scripts, fn($s) => $s['status'] === 'error')), ]; } + +function vv_rsync_status(): array { + $vars = vv_conf_vars(); + + $enabled = ($vars['RSYNC_ENABLED'] ?? 'true') !== 'false'; + + $windows = [ + 'critical' => ($vars['CRITICAL_RSYNC_ENABLED'] ?? 'false') !== 'false', + 'daily' => ($vars['DAILY_RSYNC_ENABLED'] ?? 'false') !== 'false', + 'intermediate' => ($vars['INTERMEDIATE_RSYNC_ENABLED'] ?? 'true') !== 'false', + 'weekly' => ($vars['WEEKLY_RSYNC_ENABLED'] ?? 'false') !== 'false', + ]; + + // Active rsync profiles — from lock files + $lockDir = '/tmp/unraid_locks'; + $active = []; + foreach (glob("$lockDir/rsync_*.lock") ?: [] as $lf) { + $content = trim(@file_get_contents($lf) ?: ''); + [$pid, $locked_name] = array_pad(explode(':', $content, 2), 2, ''); + if (!$pid || !file_exists("/proc/$pid")) continue; + $profile = preg_replace('/^rsync_/', '', $locked_name ?: basename($lf, '.lock')); + $active[] = [ + 'profile' => $profile, + 'pid' => (int)$pid, + 'elapsed' => time() - (int)filemtime($lf), + ]; + } + + // Last completed run per window (orchestrator log files) + $scriptMap = [ + 'critical' => 'critical_sync_maintenance', + 'daily' => 'daily_sync_maintenance', + 'intermediate' => 'intermediate_sync_maintenance', + 'weekly' => 'weekly_sync_maintenance', + ]; + $lastSync = []; + foreach ($scriptMap as $key => $scriptName) { + $logFile = LOG_DIR . "/$scriptName.json"; + if (!file_exists($logFile)) continue; + $stat = json_decode(@file_get_contents($logFile) ?: '{}', true) ?: []; + $lastSync[$key] = [ + 'ts' => (int)($stat['end'] ?? $stat['start'] ?? 0), + 'status' => $stat['status'] ?? 'unknown', + 'duration' => isset($stat['start'], $stat['end']) + ? (int)$stat['end'] - (int)$stat['start'] : null, + ]; + } + + return [ + 'enabled' => $enabled, + 'windows' => $windows, + 'active' => $active, + 'last_sync' => $lastSync, + ]; +} diff --git a/Plugin/unraid/pages/monitor.php b/Plugin/unraid/pages/monitor.php index 6ef1706..0f85fea 100644 --- a/Plugin/unraid/pages/monitor.php +++ b/Plugin/unraid/pages/monitor.php @@ -98,8 +98,18 @@