This is an application that allows admins at the clc or centers to monitor the modules people are viewing in real-time.
It's running on the port 3002
.
CDN Module Gaze monitors your existing oc4d.service
logs in real-time to track user activity across different modules. It provides live statistics, time tracking per IP address, and configurable time limits with alerts when users exceed specified durations.
- 🔴 Real-time Log Monitoring: Streams live logs from
oc4d.service
using Server-Sent Events - 📊 Live Statistics: Shows active users, modules, and session counts
- ⏱️ Time Tracking: Tracks how long each IP spends on each module (live seconds counter)
- 🚨 Time Limits & Alerts: Set time limits for specific modules with visual and alert notifications
- 🎯 Smart Module Matching: Links log module names to database module names using URL patterns
- 📱 Responsive Design: Works on desktop and mobile devices
- 🌙 Modern UI: Clean, professional interface with real-time updates
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ oc4d.service │───▶│ journalctl -f │───▶│ Next.js API │
│ │ │ (log streaming) │ │ /api/logs/stream│
└─────────────────┘ └──────────────────┘ └─────────────────┘
│
▼
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Web Browser │◀───│ Server-Sent │◀───│ Log Parser │
│ (React UI) │ │ Events (SSE) │ │ (IP + Module) │
└─────────────────┘ └──────────────────┘ └─────────────────┘
The system monitors logs with this format:
Jul 02 03:13:12 cdn oc4d[2369]: info: ::ffff:192.168.4.238 - [2024-07-02T03:13:12.202Z] "GET /modules/cdn_acid_bases_and_salts/content/index.html HTTP/1.1" 200
Extraction Process:
- IP Address: Extracts IPv4 from
::ffff:192.168.4.238
→192.168.4.238
- Module Name: Extracts from URL
/modules/cdn_acid_bases_and_salts/...
→cdn_acid_bases_and_salts
- Session Tracking: Links IP + Module to create/update user sessions
The system uses a smart matching algorithm to link log module names with database module names:
Database Module:
├── name: "Acid, Bases, And Salts"
├── indexHtmlUrl: "/modules/cdn_acid_bases_and_salts/content/index.html"
└── URL ID: "cdn_acid_bases_and_salts" (extracted from indexHtmlUrl)
Log Entry:
├── URL: "/modules/cdn_acid_bases_and_salts/content/node/lesson1.html"
└── Module ID: "cdn_acid_bases_and_salts" (extracted from URL)
Match: ✅ URL ID === Module ID
Session Management:
- One active session per IP address
- Sessions timeout after 100 minutes of inactivity
- Time tracking starts when module access is detected
- Live counter updates every second
Timer System:
- Set time limits for specific modules (by database name)
- Smart matching links timers to log sessions
- Visual indicators when limits are exceeded
- Configurable alerts and notifications
- Open the application in your browser
- Click "Start Monitoring" button
- The system begins streaming logs in real-time
- Active sessions appear in the tracking table
- Search for Module: Use the dropdown to find a module
- Set Duration: Enter time limit in minutes
- Activate Timer: Click "Set Limit" to activate
- Monitor Status: Active timers show in the dashboard
Live Tracking Table shows:
- IP addresses of active users
- Current module being accessed
- Live time counter (updates every second)
- Visual alerts when time limits exceeded
When a user exceeds a time limit:
- Time badge turns red and pulses
- Alert notification appears at top
- Console logs violation details
- Session continues tracking (doesn't stop)
To install CDN Module Gaze follow the commands below;
-
Connect the server to the internet and ssh into the server
ssh pi@cdn.local
-
Clone the repo
git clone https://github.com/ComDevNet/cdn-module-gaze.git
cd cdn-module-gaze
-
Run the Install script
chmod +x install.sh
./install.sh
-
Now all you need to do is visit
http://oc4d.cdn:3002
and click on thestart monitoring
button
Built with: Next.js 14, React 18, TypeScript, Prisma, PostgreSQL, Tailwind CSS, shadcn/ui