Dashboard Refresh Problem Fixed: - Race condition where poll.add() was called before containers existed - Containers were undefined during first poll callback - DOM updates failed silently with no error logging - Fixed by creating containers BEFORE setting up polling Debug Features Added: - Toggle debug mode with button in header - Visual debug panel showing last 20 log entries - Browser console logging with timestamps - Live update indicator (count + time since last update) - Error tracking and counting - Detailed logging of all RPC calls and responses Debug Panel Features: - Timestamps for all events - JSON data preview for API responses - Auto-scroll with newest entries at top - Max 20 entries to prevent memory issues - Hidden by default, shown when debug enabled Update Indicator: - Shows "Updates: N | Last: Xs ago" in header - Updates every second - Visual feedback that polling is working - Easy to spot stalled/broken polling Error Handling: - Try/catch around all poll callbacks - Errors logged to debug panel and console - Error counting for diagnostics - Polling continues even after errors Code Improvements: - Proper container creation order - Better error handling in load() and polling - Debug logging throughout lifecycle - Performance metrics tracking Documentation: - Complete analysis in REFRESH-DEBUG.md - Troubleshooting guide - Debug mode usage instructions - Performance considerations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
8.2 KiB
8.2 KiB
Netifyd Dashboard - Refresh & Debug Analysis
Refresh Problem Identified
Root Cause
The dashboard polling system had a race condition where:
poll.add()was called before containers were created- When the first poll callback executed,
self.statusContainer,self.statsContainer, etc. wereundefined - DOM updates failed silently because containers didn't exist yet
- No error handling or logging to detect the issue
Code Flow Issue (Before Fix)
// WRONG ORDER - This was the problem:
poll.add(function() {
// Try to update containers
if (self.statusContainer) { ... } // undefined!
});
// Containers created AFTER poll setup
self.statusContainer = E('div');
self.statsContainer = E('div');
The Fix
// CORRECT ORDER - Fixed version:
// 1. Create containers FIRST
self.statusContainer = E('div');
self.statsContainer = E('div');
self.appsContainer = E('div');
self.protosContainer = E('div');
// 2. THEN set up polling
poll.add(function() {
// Now containers exist!
if (self.statusContainer) {
dom.content(self.statusContainer, newContent);
}
});
Debug Features Added
1. Debug Mode Toggle
Button in Header: "Enable Debug" / "Disable Debug"
- Toggles debug logging to browser console
- Shows/hides debug panel with live log entries
- Changes button color (secondary → danger when enabled)
2. Debug Panel
Visual Log Display:
- Shows last 20 log entries
- Timestamp + message + JSON data
- Auto-scrolling, newest entries at top
- Monospaced font for readability
- Hidden by default, shown when debug enabled
3. Console Logging
Browser Console Output:
[NetifydDashboard 2026-01-06T17:30:00.123Z] Loading dashboard data... {...}
[NetifydDashboard 2026-01-06T17:30:00.456Z] Dashboard data loaded {...}
[NetifydDashboard 2026-01-06T17:30:00.789Z] Rendering dashboard {...}
[NetifydDashboard 2026-01-06T17:30:05.123Z] Polling for updates... (interval: 5s)
[NetifydDashboard 2026-01-06T17:30:05.456Z] Poll update #1 {...}
4. Update Indicator
Live Status Display:
- Shows in header: "Updates: 5 | Last: 3s ago"
- Updates every second
- Counts total poll updates
- Shows seconds since last update
- Visual feedback that polling is working
5. Error Tracking
Error Handling:
- Catches poll errors with try/catch
- Logs errors to debug panel
- Counts total errors:
self.errorCount - Includes error message and stack trace
- Doesn't break polling on error
Debug Data Logged
On Load
{
"dashboard": {
"service": { "running": true, "uptime": 123 },
"stats": { "active_flows": 25, "unique_devices": 6 }
},
"status": { "running": true, "version": "5.2.1" },
"apps": 3,
"protocols": 3
}
On Poll Update
{
"flows": 25,
"devices": 6,
"apps": 3
}
On Error
{
"error": "RPC call failed: Connection timeout",
"stack": "Error: RPC call failed...\n at ..."
}
Metrics Tracked
updateCount: Total number of successful pollserrorCount: Total number of failed pollslastUpdate: Timestamp of last successful updaterefreshInterval: Polling interval in seconds (default: 5)
How to Use Debug Mode
Enable Debug
- Open Netifyd Dashboard
- Click "Enable Debug" button in top-right
- Debug panel appears below description
- Console logs start appearing
What to Look For
Healthy Dashboard:
Updates: 12 | Last: 2s ago
- Update count increasing every 5 seconds
- Last update time stays under 5 seconds
Problem Indicators:
Updates: 0 | Last: never
- No updates happening
- Check console for errors
Updates: 5 | Last: 45s ago
- Polling stopped or stalled
- Check for JavaScript errors in console
Debug Log Entries
Normal Operation:
2026-01-06T17:30:00.123Z Loading dashboard data...
2026-01-06T17:30:00.456Z Dashboard data loaded
2026-01-06T17:30:00.789Z Rendering dashboard
2026-01-06T17:30:05.123Z Polling for updates... (interval: 5s)
2026-01-06T17:30:05.456Z Poll update #1
2026-01-06T17:30:10.456Z Poll update #2
With Errors:
2026-01-06T17:30:05.123Z Polling for updates... (interval: 5s)
2026-01-06T17:30:05.456Z Poll error #1
{
"error": "RPC call failed",
"stack": "Error: ..."
}
Polling Configuration
Current Settings
- Interval: 5 seconds (
refreshInterval: 5) - Data Sources:
- Dashboard stats (flows, devices, traffic)
- Service status (running, uptime, version)
- Top applications (DPI detected apps)
- Top protocols (TCP/UDP/ICMP breakdown)
Changing Poll Interval
Edit dashboard.js:
return view.extend({
refreshInterval: 10, // Change to 10 seconds
// ...
});
Valid range: 1-60 seconds (recommended: 5-10)
Troubleshooting
Dashboard Not Updating
- Enable debug mode
- Check update indicator
- Look for errors in console
- Check RPC backend is responding:
ssh root@router 'ubus call luci.secubox-netifyd get_dashboard'
High Update Count, No Data Changes
Possible causes:
- Netifyd service running but no network traffic
- Network interfaces not being monitored
- Flow data not being captured
Solutions:
- Check
netifyd -soutput on router - Verify interfaces are configured
- Generate some network traffic (ping, wget, etc.)
Errors in Debug Log
Common errors:
- "RPC call failed" → Backend not responding
- "Connection timeout" → Network issue
- "Method not found" → RPC method missing
Performance Considerations
Debug Mode Impact
- Console logging: Minimal (<1% CPU)
- Debug panel: Small DOM updates (~0.5 KB per entry)
- Memory: Max 20 entries × ~200 bytes = 4 KB
Polling Impact
- Network: ~1 KB per poll (4 RPC calls)
- CPU: <1% (JSON parsing + DOM updates)
- Recommended for: Production use
Reducing Impact
If needed, increase interval:
refreshInterval: 10, // Less frequent updates
Code Architecture
Component Structure
dashboard.js
├── State Management
│ ├── debugMode (boolean)
│ ├── updateCount (number)
│ ├── errorCount (number)
│ └── lastUpdate (Date)
│
├── Debug Functions
│ ├── debug(message, data) - Log entry
│ └── toggleDebug(ev) - Toggle on/off
│
├── Data Loading
│ ├── load() - Initial load with debug
│ └── poll callback - Auto-refresh with debug
│
└── Rendering
├── render() - Main layout + debug panel
├── renderServiceStatus() - Status card
├── renderStatistics() - Metrics cards
├── renderTopApplications() - App chart
└── renderTopProtocols() - Protocol chart
Polling Flow
[Page Load]
↓
load() - Fetch initial data
↓
render() - Create DOM + containers
↓
poll.add() - Register polling callback
↓
[Every 5 seconds]
↓
Poll callback executes
↓
Fetch fresh data (4 RPC calls)
↓
Update containers via dom.content()
↓
Update debug log & indicator
↓
[Repeat]
Future Enhancements
Potential Additions
- Export Debug Log - Download as JSON/text file
- Pause/Resume Polling - Manual control
- Poll Interval Slider - UI control (1-60s)
- Health Score - Green/yellow/red indicator
- Network Stats Graph - Real-time chart
- Alert Thresholds - Notify on high traffic
- Debug Filters - Show only errors/warnings
- Performance Metrics - RPC response times
API Enhancement Ideas
- Batch RPC Calls - Single call for all data
- Delta Updates - Only send changed data
- Compression - Reduce network overhead
- Caching - Client-side data retention
Summary
The refresh problem was caused by a race condition where polling started before DOM containers existed. The fix ensures containers are created first, then polling is initialized. Debug mode provides comprehensive visibility into the polling system, making future issues easy to diagnose.
Key Improvements:
- ✅ Fixed container creation order
- ✅ Added error handling to polls
- ✅ Added visual debug panel
- ✅ Added console logging
- ✅ Added update indicator
- ✅ Added error counting
- ✅ Zero production impact when debug disabled