Advanced analytics system for HazeBot Admin Panel with SQLite database, partitioning, and real-time visualization.
Interactive HTML dashboard with real-time analytics, session tracking, and feature usage insights.
Quick Start:
python view_analytics.pyOpens dashboard at http://localhost:8089 with JWT authentication support.
- User Analytics - Total users, active users (7d/30d), new users
- Session Tracking - Real-time active sessions, average duration, total actions
- Platform Stats - Web, Android, iOS breakdown with version tracking
- Feature Usage - Top endpoints, route popularity, API call statistics
- Active Sessions - Real-time list with last activity timestamps
- Session Details - Individual session drill-down (actions, duration, platform)
- Peak Hours Analysis - 24h activity heatmap
- User Growth Chart - Daily/weekly trend visualization
- Device Distribution - Platform and version breakdown
- Time Range Filters - 7d/30d/90d/all time views
- Auto-Refresh - Optional 30s updates for live monitoring
- 📈 User Growth - Daily active users over time
- 📱 Platform Distribution - Web vs Mobile (Android/iOS)
- 🔥 Top Features - Most used endpoints and routes
- ⏰ Peak Usage - Hour-by-hour activity patterns
- 👥 Active Sessions - Real-time session list with details
# Default (port 8089, JWT auth)
python view_analytics.py
# Custom port
python view_analytics.py --port 9000
# Custom host (for network access)
python view_analytics.py --host 0.0.0.0
# No auto-browser
python view_analytics.py --no-browserThe dashboard is protected by JWT authentication (admin/mod roles only). See ANALYTICS_JWT_SETUP.md for setup instructions.
analytics_dashboard.html- Interactive dashboard with Chart.jsview_analytics.py- Flask server with API endpointslogin.html- JWT authentication login page
json_to_sqlite.py- Migration tool (JSON → SQLite)reprocess_analytics.py- Rebuild analytics from raw sessions
../api/analytics.py- Session tracking and event logging../api/analytics_db.py- SQLite database operations../api/analytics_partitioning.py- Table partitioning for performance../api/feature_analytics.py- Feature usage tracking
test_api_endpoints.py- API endpoint testingtest_partitioning.py- Database partitioning teststest_performance.py- Performance benchmarks
ANALYTICS_JWT_SETUP.md- JWT authentication setup guideDEPLOYMENT_SUMMARY.md- Deployment checklistREADME.md- This file
Analytics data is stored in SQLite with the following tables:
sessions- User sessions (id, user_id, device_info, timestamps)session_actions- Individual actions (session_id, endpoint, timestamp)active_sessions- Real-time session tracking (last_activity, is_active)
sessions_YYYYMM- Archived session datasession_actions_YYYYMM- Archived action data
aggregated_metrics- Pre-computed stats for fast queriesdaily_metrics- Daily rollup data
Legacy JSON files (app_analytics.json) are automatically migrated to SQLite on first run.
User Action → Flask API (analytics.py)
↓
Track Session (analytics_db.py)
↓
SQLite Database (app_analytics.db)
↓
Dashboard API (view_analytics.py)
↓
HTML Dashboard (analytics_dashboard.html)
- Dark Mode - Modern slate/navy theme (#0f172a, #1e293b, #334155)
- Responsive - Optimized for desktop, tablet, and mobile
- Compact Layout - Maximum information density
- Interactive - Hover tooltips, clickable legends, drill-down views
- Real-time Updates - Auto-refresh with visual indicators
- JWT Authentication - Admin/mod role required
- NGINX Integration -
auth_requestdirective for token verification - Bitwarden Support - Password manager auto-fill compatible
- Session Management - Secure token storage and validation
The analytics server provides REST API endpoints:
GET /api/stats- Overview metrics (users, sessions, actions)GET /api/active-sessions- Real-time active sessions listGET /api/session/<session_id>- Individual session detailsGET /api/chart/user-growth- User growth time seriesGET /api/chart/devices- Device distribution dataGET /api/chart/features- Top features usageGET /api/chart/peak-hours- Hourly activity breakdown
All endpoints support ?days=N parameter (7, 30, 90, or omit for all-time).
- Partitioning - Monthly table partitioning for fast queries
- Indexing - Optimized indexes on user_id, timestamp, session_id
- Caching - Aggregated metrics for instant dashboard load
- Pagination - Large result sets are paginated
- Dashboard load: <100ms (cached metrics)
- Active sessions: <50ms (indexed queries)
- Session details: <20ms (direct lookup)
- Chart data: <200ms (pre-aggregated)
- Production-Ready - Deployed with JWT auth and NGINX
- Scalable - SQLite handles millions of events efficiently
- Maintainable - Automated partitioning and cleanup
- Observable - Detailed logging and error tracking
- Documented - Comprehensive setup guides included
# Archive old data (older than 90 days)
python analytics_partitioning.py --archive
# Vacuum database (reclaim space)
sqlite3 ../Data/app_analytics.db "VACUUM;"# Rebuild all analytics from session data
python reprocess_analytics.py# Migrate legacy JSON to SQLite
python json_to_sqlite.py- Setup:
ANALYTICS_JWT_SETUP.md- Complete JWT authentication and deployment guide - Deployment:
DEPLOYMENT_SUMMARY.md- Quick reference deployment checklist - Browser Helper:
browser_helper.js- Console helper functions for testing
- API:
../api/README.md- Backend API endpoints and WebSocket documentation - Main README:
../README.md- HazeBot overview and general setup - Bot Setup:
../docs/BOT_SETUP.md- Discord bot installation guide