unclecode
e2af031b09
feat(monitor): add real-time monitoring dashboard with Redis persistence
...
Complete observability solution for production deployments with terminal-style UI.
**Backend Implementation:**
- `monitor.py`: Stats manager tracking requests, browsers, errors, timeline data
- `monitor_routes.py`: REST API endpoints for all monitor functionality
- GET /monitor/health - System health snapshot
- GET /monitor/requests - Active & completed requests
- GET /monitor/browsers - Browser pool details
- GET /monitor/endpoints/stats - Aggregated endpoint analytics
- GET /monitor/timeline - Time-series data (memory, requests, browsers)
- GET /monitor/logs/{janitor,errors} - Event logs
- POST /monitor/actions/{cleanup,kill_browser,restart_browser} - Control actions
- POST /monitor/stats/reset - Reset counters
- Redis persistence for endpoint stats (survives restart)
- Timeline tracking (5min window, 5s resolution, 60 data points)
**Frontend Dashboard** (`/dashboard`):
- **System Health Bar**: CPU%, Memory%, Network I/O, Uptime
- **Pool Status**: Live counts (permanent/hot/cold browsers + memory)
- **Live Activity Tabs**:
- Requests: Active (realtime) + recent completed (last 100)
- Browsers: Detailed table with actions (kill/restart)
- Janitor: Cleanup event log with timestamps
- Errors: Recent errors with stack traces
- **Endpoint Analytics**: Count, avg latency, success%, pool hit%
- **Resource Timeline**: SVG charts (memory/requests/browsers) with terminal aesthetics
- **Control Actions**: Force cleanup, restart permanent, reset stats
- **Auto-refresh**: 5s polling (toggleable)
**Integration:**
- Janitor events tracked (close_cold, close_hot, promote)
- Crawler pool promotion events logged
- Timeline updater background task (5s interval)
- Lifespan hooks for monitor initialization
**UI Design:**
- Terminal vibe matching Crawl4AI theme
- Dark background, cyan/pink accents, monospace font
- Neon glow effects on charts
- Responsive layout, hover interactions
- Cross-navigation: Playground ↔ Monitor
**Key Features:**
- Zero-config: Works out of the box with existing Redis
- Real-time visibility into pool efficiency
- Manual browser management (kill/restart)
- Historical data persistence
- DevOps-friendly UX
Routes:
- API: `/monitor/*` (backend endpoints)
- UI: `/dashboard` (static HTML)
2025-10-17 21:36:25 +08:00
unclecode
b97eaeea4c
feat(docker): implement smart browser pool with 10x memory efficiency
...
Major refactoring to eliminate memory leaks and enable high-scale crawling:
- **Smart 3-Tier Browser Pool**:
- Permanent browser (always-ready default config)
- Hot pool (configs used 3+ times, longer TTL)
- Cold pool (new/rare configs, short TTL)
- Auto-promotion: cold → hot after 3 uses
- 100% pool reuse achieved in tests
- **Container-Aware Memory Detection**:
- Read cgroup v1/v2 memory limits (not host metrics)
- Accurate memory pressure detection in Docker
- Memory-based browser creation blocking
- **Adaptive Janitor**:
- Dynamic cleanup intervals (10s/30s/60s based on memory)
- Tiered TTLs: cold 30-300s, hot 120-600s
- Aggressive cleanup at high memory pressure
- **Unified Pool Usage**:
- All endpoints now use pool (/html, /screenshot, /pdf, /execute_js, /md, /llm)
- Fixed config signature mismatch (permanent browser matches endpoints)
- get_default_browser_config() helper for consistency
- **Configuration**:
- Reduced idle_ttl: 1800s → 300s (30min → 5min)
- Fixed port: 11234 → 11235 (match Gunicorn)
**Performance Results** (from stress tests):
- Memory: 10x reduction (500-700MB × N → 270MB permanent)
- Latency: 30-50x faster (<100ms pool hits vs 3-5s startup)
- Reuse: 100% for default config, 60%+ for variants
- Capacity: 100+ concurrent requests (vs ~20 before)
- Leak: 0 MB/cycle (stable across tests)
**Test Infrastructure**:
- 7-phase sequential test suite (tests/)
- Docker stats integration + log analysis
- Pool promotion verification
- Memory leak detection
- Full endpoint coverage
Fixes memory issues reported in production deployments.
2025-10-17 20:38:39 +08:00