A real-time game statistics processing platform with machine learning capabilities
GameStatsPx is a distributed real-time data processing platform designed to collect, process, and analyze game statistics using modern data engineering tools and machine learning techniques.
- Features
- Architecture
- Prerequisites
- Installation
- Quick Start
- Project Structure
- Configuration
- Usage
- Documentation
- Monitoring
- Troubleshooting
- Contributing
- License
- Real-time Data Pipeline: Stream processing with Apache Kafka
- Machine Learning: Linear and non-linear regression models using Apache Spark
- Distributed Architecture: Microservices-based design with Docker
- Data Storage: Elasticsearch for indexing and fast querying
- Visualization: Kibana dashboards for real-time analytics
- Log Processing: Fluent Bit for centralized log aggregation
- Monitoring: Kafka UI for message queue monitoring
- Scalable: Horizontal scaling capabilities at multiple layers
- Security: X-Pack security with authentication and RBAC
┌─────────────┐
│ Crawler │ ──── Scrapes game data
└──────┬──────┘
│ logs
▼
┌─────────────┐
│ Fluent Bit │ ──── Aggregates & forwards
└──────┬──────┘
│ stream
▼
┌─────────────┐
│ Kafka │ ──── Message queue (Topic: gameStatsPx)
└──────┬──────┘
│ consume
▼
┌─────────────┐
│ Spark │ ──── ML predictions (Linear & Non-linear regression)
└──────┬──────┘
│ results
▼
┌──────────────┐
│Elasticsearch │ ──── Storage & indexing
└──────┬───────┘
│
▼
┌─────────────┐
│ Kibana │ ──── Visualization
└─────────────┘
For a detailed architecture diagram, see architecture.
- Docker 20.10+
- Docker Compose 1.29+
- Python 3.8+
- Git
git clone git@github.com:makapx/gameStatsPx.git
cd gameStatsPxcd gamges-crawler
mv config.example.json config.jsonSet your credential into config.json file
docker-compose up -dThis command will start all services in detached mode:
- Kafka (with KRaft)
- Kafka UI
- Fluent Bit
- Elasticsearch
- Kibana
- Spark
- Games Crawler
docker-compose psAll services should show status as "Up".
Before running the initialization script, you need to set up a Python virtual environment:
# Navigate to the games-crawler directory
cd games-crawler
# Create a virtual environment
python3 -m venv venv
# Activate the virtual environment
# On Linux/macOS:
source venv/bin/activate
# On Windows:
# venv\Scripts\activate
# Install required dependencies
pip install elasticsearch requests
# Run the initialization script
python dataset_gen.py
# Deactivate virtual environment when done
deactivate
# Return to project root
cd ..- Kafka UI: http://localhost:8585
- Kibana: http://localhost:5601
- Elasticsearch: http://localhost:9200
Elasticsearch:
- Username:
elastic - Password:
changeme
Kibana:
- Username:
kibana_system_user - Password:
kibanapass123
gameStatsPx/
├── README.md
├── docker-compose.yml # Main orchestration
├── README.md # This file
├── games-crawler/ # Data collection
│ ├── Dockerfile
│ ├── dataset_gen.py # Dataset
│ ├── games.py # Crawler
├── spark/ # Apache Spark ML
│ ├── Dockerfile
├── fluent-bit/ # Log processing
│ └── fluent-bit.conf
└── docs/ # Documentation
├── architecture.svg # Architecture diagram
├── doc.ipynb # Jupyter presentation
Kafka is configured in KRaft mode (no Zookeeper required).
- Broker ID: 1
- Topic:
gameStatsPx(auto-created) - Partitions: 1
- Replication Factor: 1
- Cluster Mode: Single-node
- Heap Size: 512MB (Xms/Xmx)
- Security: X-Pack enabled
- Port: 9200
The Spark service implements:
- Linear Regression: For linear relationships in game statistics
- Non-Linear Regression: For complex patterns and predictions
Output datasets are stored in ./spark/data/container_data/.
# Start all services
docker-compose up -d
# Start specific service
docker-compose up -d kafka# Stop all services
docker-compose down
# Stop and remove volumes (WARNING: deletes data)
docker-compose down -v# View all logs
docker-compose logs -f
# View specific service logs
docker-compose logs -f spark
docker-compose logs -f kafka
docker-compose logs -f elasticsearch# Restart all services
docker-compose restart
# Restart specific service
docker-compose restart kafka# Rebuild all containers
docker-compose build
# Rebuild specific container
docker-compose build crawler
# Rebuild and restart
docker-compose up -d --buildThe project includes a comprehensive Jupyter notebook presentation.
# Navigate to docs directory
cd docs
# Create a virtual environment
python3 -m venv venv
# Activate the virtual environment
# On Linux/macOS:
source venv/bin/activate
# On Windows:
# venv\Scripts\activate
# Install Jupyter
pip install jupyter
# Start Jupyter
jupyter notebook doc.ipynb
# Deactivate when done
deactivateYou can convert the notebook to a presentation:
jupyter nbconvert doc.ipynb --to slides --post serveAccess Kafka UI at http://localhost:8585 to:
- View topics and partitions
- Monitor consumer groups
- Check message throughput
- Inspect message content
# Check cluster health
curl -u elastic:changeme http://localhost:9200/_cluster/health?pretty
# List indices
curl -u elastic:changeme http://localhost:9200/_cat/indices?v
# Get cluster stats
curl -u elastic:changeme http://localhost:9200/_cluster/stats?pretty- Navigate to http://localhost:5601
- Log in with credentials
- Go to Management → Stack Management → Index Patterns
- Create index patterns for your data (
games) - Use Discover and Dashboard to visualize data
- Import
games_dashboard.ndjsontoKibana > Saved Objectsto see the dashboard I create
Check Docker:
docker --version
docker-compose --versionCheck logs:
docker-compose logs [service-name]Verify Elasticsearch is running:
docker-compose ps elasticsearchCheck health:
curl http://localhost:9200/_cluster/healthCheck if Kafka is running:
docker exec kafka kafka-topics --list --bootstrap-server localhost:39092View Kafka logs:
docker-compose logs -f kafkaEnsure virtual environment is activated:
# In games-crawler directory
source venv/bin/activate # Linux/macOS
# or
venv\Scripts\activate # WindowsVerify dependencies:
pip list | grep -E "elasticsearch|requests"If ports are already in use, modify docker-compose.yml:
ports:
- "8585:8080" # Change 8585 to another portIf services crash due to memory:
Increase Docker memory:
- Docker Desktop → Settings → Resources → Memory
- Increase to at least 8GB
Reduce Elasticsearch heap:
environment:
- "ES_JAVA_OPTS=-Xms256m -Xmx256m" # Reduce from 512m

