function monitorApp() { return { // Data lastUpdate: 'Never', queue: { pending: 0, running: 0, completed: 0, failed: 0 }, runningJobs: [], worker: { cpu_percent: 0, gpu_percent: 0, memory_mb: 0, memory_percent: 0, active_processors: 0, max_processors: 6, processors: [] }, // Initialize init() { this.refresh(); setInterval(() => this.refresh(), 5000); }, // Refresh all data async refresh() { await Promise.all([ this.fetchQueueStats(), this.fetchRunningJobs(), this.fetchWorkerStatus() ]); this.lastUpdate = new Date().toLocaleTimeString(); }, // Fetch queue stats async fetchQueueStats() { try { const res = await fetch('/api/v1/monitor/queue_stats'); this.queue = await res.json(); } catch (e) { console.error('Failed to fetch queue stats:', e); } }, // Fetch running jobs async fetchRunningJobs() { try { const res = await fetch('/api/v1/monitor/running_jobs'); const data = await res.json(); this.runningJobs = data.jobs; } catch (e) { console.error('Failed to fetch running jobs:', e); } }, // Fetch worker status async fetchWorkerStatus() { try { const res = await fetch('/api/v1/monitor/worker_status'); this.worker = await res.json(); } catch (e) { console.error('Failed to fetch worker status:', e); } }, // Helper functions getPhaseName(phase) { const names = { 1: 'Foundation', 2: 'Core Processing', 3: 'Deep Analysis', 4: 'Knowledge Building' }; return names[phase] || ''; }, getProcessorIcon(status) { const icons = { 'completed': 'βœ…', 'running': 'πŸ”„', 'pending': '⏸️', 'deferred': '⏸️', 'failed': '❌' }; return icons[status] || '❓'; }, getProcessorColor(status) { const colors = { 'completed': 'bg-green-500', 'running': 'bg-blue-500', 'pending': 'bg-gray-500', 'deferred': 'bg-yellow-500', 'failed': 'bg-red-500' }; return colors[status] || 'bg-gray-500'; }, formatDuration(secs) { if (!secs) return '0s'; const m = Math.floor(secs / 60); const s = Math.floor(secs % 60); return m > 0 ? `${m}m ${s}s` : `${s}s`; } } }