A sophisticated service that generates realistic mock traffic for OpenPanel analytics. Uses BullMQ to schedule and process visitor journeys with intelligent timing based on hourly traffic patterns.
- Smart Visitor Spawning: Intelligent logic that spawns visitors based on hourly traffic targets
- Realistic User Journeys: Multiple predefined visitor types with weighted selection
- Random Event Timing: Natural delays between user actions (2-15 seconds)
- Hourly Traffic Profiles: 24-hour visitor distribution patterns
- BullMQ Integration: Robust job queuing with Redis backend
- Functional Programming: Clean, modular architecture
- Real-time Monitoring: Status dashboard with traffic insights
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Cron Job │ │ Visitor Logic │ │ Event Templates │
│ (Every 1s) │───▶│ (Smart Spawn) │───▶│ (Journeys) │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│ │ │
▼ ▼ ▼
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ BullMQ Queue │ │ Visitor Worker │ │ OpenPanel API │
│ (Redis) │───▶│ (Process Jobs) │───▶│ (Events) │
└─────────────────┘ └──────────────────┘ └─────────────────┘
- Bouncer (35% weight) - Quick exit after homepage
- Basic (30% weight) - Homepage + About page
- Blog Reader (25% weight) - Reads blog posts with engagement
- Product Explorer (20% weight) - Explores products and demos
- Docs User (15% weight) - Documentation focused journey
- Deep Explorer (5% weight) - Comprehensive site exploration
The service uses a realistic 24-hour traffic distribution:
Peak Hours (9-17): 12-20 visitors/hour
Evening (18-23): 6-12 visitors/hour
Night (0-5): 1-3 visitors/hour
Morning (6-8): 3-8 visitors/hour
- Option 1 (Docker): Docker and Docker Compose
- Option 2 (Local): Bun runtime, Redis server, OpenPanel account (optional)
-
Clone the repository and configure:
git clone <your-repo> cd openpanel-mock
-
Create environment file (optional):
cp .env.example .env # Edit .env with your OpenPanel credentials
-
Start with Docker Compose:
# Start the service with Redis docker-compose up -d # View logs docker-compose logs -f openpanel-mock # Optional: Start with Redis monitoring docker-compose --profile monitoring up -d
-
Access services:
- OpenPanel Mock Service: Running in container
- Redis Commander (monitoring): http://localhost:8081
-
Install Bun runtime:
curl -fsSL https://bun.sh/install | bash
-
Install dependencies:
bun install
-
Start Redis server:
# macOS with Homebrew brew services start redis # Or with Docker docker run -d -p 6379:6379 redis:alpine
-
Configure environment:
Edit
config.ts
to set your OpenPanel credentials:openpanel: { clientId: 'your_client_id_here', clientSecret: 'your_client_secret_here', apiUrl: 'https://api.openpanel.dev', projectId: 'your_project_id_here', }
-
Start the service:
bun start # or for development with auto-reload bun run dev
# Start everything
docker-compose up -d
# View logs in real-time
docker-compose logs -f openpanel-mock
# Stop the service
docker-compose down
bun start
The service will:
- Start cron and visitor workers
- Schedule jobs to run every second
- Display a status dashboard every 30 seconds
- Show real-time visitor activity
🚀 Starting OpenPanel Mock Service...
📊 Configuration: { redisUrl: 'redis://localhost:6379', ... }
🔧 Starting services...
🚀 [Cron Worker] Started and ready to process jobs
🚀 [Visitor Worker] Started and ready to process visitor journeys
⏰ [Scheduler] Setting up cron job to run every second...
✅ [Scheduler] Cron job scheduled successfully
✅ All services started successfully!
📈 OpenPanel Mock Service is now generating traffic...
🎯 Current hour (14:00): Target 14 visitors
🕐 [Cron] Checking if we should spawn new visitors...
👤 [Cron] Spawning new visitor: visitor_1703123456789_abc123def with 5 events
📤 [Visitor] visitor_1703123456789_abc123def - Event 1/5 sent: screen_view (/)
⏱️ [Visitor] visitor_1703123456789_abc123def - Waiting 8s before next event...
- Redis Commander: Access web interface at http://localhost:8081 (with monitoring profile)
- Service Logs:
docker-compose logs -f openpanel-mock
- Redis Logs:
docker-compose logs -f redis
- Redis CLI: Monitor job queues with
redis-cli monitor
- Status Dashboard: Displayed every 30 seconds in console
- Real-time Events: Each visitor action is logged as it happens
Modify CONFIG.hourlyVisitorProfile
in config.js
:
hourlyVisitorProfile: [
2, // 00:00 - Low traffic
1, // 01:00 - Very low
// ... customize for your needs
20, // 12:00 - Lunch peak
// ...
]
Add new visitor journeys in src/utils/eventTemplates.js
:
newJourneyType: [
{ type: 'screen_view', path: '/custom-page' },
{ type: 'event', name: 'custom_action', properties: { value: 100 } },
],
Adjust delays in src/utils/eventTemplates.js
:
export const getRandomDelay = (min = 1000, max = 8000) => {
return Math.floor(Math.random() * (max - min + 1)) + min;
};
To send events to actual OpenPanel API, uncomment and modify the real API method in src/services/openpanelClient.js
:
async sendEventToRealAPI(event) {
const response = await fetch(`${this.apiUrl}/events`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${this.clientSecret}`,
},
body: JSON.stringify({
project_id: this.projectId,
...event,
}),
});
// ... handle response
}
Press Ctrl+C
for graceful shutdown. The service will:
- Stop all cron jobs
- Close worker connections
- Clean up Redis queues
├── config.js # Main configuration
├── src/
│ ├── index.js # Main entry point
│ ├── scheduler.js # BullMQ cron job setup
│ │ ├── cronJob.js # Cron job processor
│ │ └── visitorJob.js # Visitor journey processor
│ ├── services/
│ │ └── openpanelClient.js # OpenPanel API client
│ └── utils/
│ ├── eventTemplates.js # Visitor journey templates
│ └── visitorLogic.js # Smart spawning logic
└── package.json
MIT