cd netsage-ml
# Activate virtual environment (if not already activated)
source venv/bin/activate # macOS/Linux
# OR
venv\Scripts\activate # Windows
# Install dependencies (if not done)
pip install -r requirements.txt# Ensure .env file exists
cp .env.example .env
# Train the ML model (creates ml_engine/models/isolation_forest.pkl)
python scripts/train_iforest.pyMake sure these are running before starting the services:
# Check MongoDB
mongosh --eval "db.version()" # Should show version number
# Check Kafka (if installed locally)
kafka-topics.sh --list --bootstrap-server localhost:9092Open 4 separate terminal windows/tabs:
cd netsage-ml
source venv/bin/activate
python -m uvicorn api.main:app --reload --port 8000✅ Check: http://localhost:8000/docs
cd netsage-ml
source venv/bin/activate
python kafka/consumer.py✅ Check: Should see "🎯 Kafka consumer started" and processing messages
cd netsage-ml
source venv/bin/activate
python kafka/producer.py✅ Check: Should see "✅ Sent: ..." messages every 0.5 seconds
cd netsage-ml/dashboard
npm install # First time only
npm start # or: npm run dev✅ Check: http://localhost:3000
Open your browser: http://localhost:3000
You should see:
- Real-time network flow metrics
- Anomaly alerts (if any detected)
- Charts and statistics
# Terminal 1 - API
cd netsage-ml && source venv/bin/activate && python -m uvicorn api.main:app --reload --port 8000
# Terminal 2 - Consumer
cd netsage-ml && source venv/bin/activate && python kafka/consumer.py
# Terminal 3 - Producer
cd netsage-ml && source venv/bin/activate && python kafka/producer.py
# Terminal 4 - Dashboard
cd netsage-ml/dashboard && npm start- Python virtual environment activated
- MongoDB running on
localhost:27017 - Kafka running on
localhost:9092(or configure.env) - Model trained (
ml_engine/models/isolation_forest.pklexists) - FastAPI running on port 8000
- Kafka consumer running and processing
- Kafka producer sending data
- React dashboard running on port 3000
curl http://localhost:8000/health
# Should return: {"status":"healthy","database":"connected"}Open: http://localhost:8000/docs
Open: http://localhost:3000
Terminal 3 should show:
✅ Sent: 10.10.0.25 -> 10.20.0.10 (2048 bytes)
✅ Sent: 10.10.0.30 -> 10.20.0.15 (15360 bytes)
Terminal 2 should show:
✓ Normal flow: 10.10.0.25 -> 10.20.0.10
🚨 ANOMALY DETECTED: 10.10.0.30 -> 10.20.0.15 (score: 0.8500)
Solution:
source venv/bin/activate
pip install -r requirements.txtSolution:
python scripts/train_iforest.pySolution:
# Start MongoDB (macOS with Homebrew)
brew services start mongodb-community
# Or check if running
mongosh --eval "db.version()"Solution:
# Update .env with correct Kafka broker
# Or start Kafka if installed locallySolution:
# Make sure Kafka producer is running (Terminal 3)
# Or seed mock data:
python scripts/seed_mock_data.pySolution:
- Check FastAPI is running on port 8000
- Check browser console for CORS errors
- Verify
vite.config.jshas correct proxy settings
To populate the dashboard with sample data:
source venv/bin/activate
python scripts/seed_mock_data.pyThis creates:
- 1,000 sample flows
- 50 sample anomalies
Refresh the dashboard to see the data!
Once everything is running:
- React Dashboard: http://localhost:3000
- FastAPI Backend: http://localhost:8000
- API Documentation: http://localhost:8000/docs
- Health Check: http://localhost:8000/health
- Alerts API: http://localhost:8000/api/alerts/
- Stats API: http://localhost:8000/api/stats/baseline
Press Ctrl+C in each terminal to stop:
- Stop producer (Terminal 3)
- Stop consumer (Terminal 2)
- Stop dashboard (Terminal 4)
- Stop FastAPI (Terminal 1)
- Run in Background: Use
tmuxorscreento keep services running - Check Logs: Each service prints status messages
- Monitor MongoDB: Use
mongoshto query data - Custom Dataset: See
DATASET_GUIDE.mdfor training on your data
You'll know everything is working when:
- ✅ All 4 terminals show running services
- ✅ Dashboard loads at http://localhost:3000
- ✅ Producer shows "✅ Sent: ..." messages
- ✅ Consumer shows flow processing
- ✅ Dashboard displays metrics and charts
- ✅ Anomalies appear in dashboard when detected
Happy detecting! 🚨