Mirko Milovanovic 9e125bf9f7
Some checks failed
Build and Push Docker Image / build (push) Has been cancelled
feat: include sleep to wait for driver setup logic and remove yaspin
2025-02-22 18:21:56 +01:00

PeerTube collector

peertube-collector is a project designed to collect and analyze WebRTC statistics from a Chromium browser and export them to a MongoDB service. This project includes a Docker setup for running the necessary services.

Prerequisites

Linux based OS with the following:

Software:

  • Docker Engine Community version is required. To install Docker CE, follow the official install instructions.

Ports:

External (OPTIONAL PROBABLY NOT NEEDED!!!):

These ports are actively used by selenium and the collector services.

  • 50000:60000/udp (WebRTC)
    • WebRTC NAT traversal requires a range of ports to be open. The range needs to be fairly large since the port is chosen randomly by the STUN server.
  • 27107/tcp (MongoDB)

Ports can be opened in the host machine's firewall with:

ufw allow 50000:60000/udp
ufw allow 27107/tcp

Setup with Docker Compose

  1. Clone the repository:
    git clone <repository-url>
    cd peertube-collector
    
  2. Create and configure the environment file based on the .env.example file:
    cp .env.example .env
    
  3. Ajust the firewall settings to allow the necessary ports if needed
  4. Start the Docker containers:
    docker compose up --abort-on-container-failure
    

The collector will start gathering WebRTC stats from the Selenium container and sending them to the Telegraf service.

To stop the Docker containers run: docker compose down -v

Setup with Monolithic image:

  1. Clone the repository:
    git clone <repository-url>
    cd peertube-collector
    
  2. Create and configure the environment file based on the .env.example file:
    cp .env.example .env
    
  3. Ajust the firewall settings to allow the necessary ports if needed
  4. Start the Docker container:
    docker run --rm -p 7900:7900 --env-file .env --name peertube-collector gitea.kobim.cloud/kobim/peertube-collector-monolith:latest
    

Environment Variables

Environment Variable Service Default Value Description
TELEGRAF_HOSTNAME telegraf None, must be set Hostname used to identify the host/user between sessions
TELEGRAF_MONGODB_DSN telegraf mongodb://stats_user... DSN for the MongoDB service
TELEGRAF_MONGODB_DATABASE telegraf statistics Database name for the MongoDB service
VIDEO_URL collector https://tube.kobim.cloud/... URL for the video to be analyzed
HUB_URL collector None URL for the Selenium Hub. If not set, the local Chrome driver will be used
SOCKET_URL collector localhost Socket URL for Telegraf service
SOCKET_PORT collector & telegraf 8094 Socket port for Telegraf service
WEBRTC_INTERNALS_PATH collector None Absolute path for WebRTC internals exporter extension. When not set the extension path is construced relative to the current main script location.
WEBRTC_INTERNALS_EXPORTER_URL WebRTC extension http://localhost:9092 Server URL for the WebRTC internals exporter extension

Variables can be set in the .env file. An example configuration is provided in the .env.example file.

Monitoring

A noVNC server is available at http://localhost:7900 to monitor the Selenium container. The password is secret.

Components

Docker Compose

The docker-compose.yml file defines the following services:

  • selenium: Runs a Selenium standalone Chromium container.
  • telegraf: Collects and sends metrics to the specified output.
  • collector: Runs the main Python application to collect WebRTC stats.

Dockerfile

The Dockerfile sets up the Python environment and installs the necessary dependencies to run the main.py script.

Monolithic Dockerfile

Monolith.dockerfile is a single Dockerfile that combines the Selenium, Telegraf, and Collector services into a single container. This is useful for deployment in a single container environment.

Main Python Script

The main.py script sets up the Selenium WebDriver, collects WebRTC stats, and sends them to the Telegraf service.

WebRTC Internals Exporter

The webrtc-internals-exporter directory contains a Chromium extension that collects WebRTC stats from the browser. It uses Webpack to replace the server collector endpoint with an environment variable.

Credits

Description
No description provided
Readme MIT 1.7 GiB
Languages
Python 39.2%
JavaScript 28.7%
Shell 24.9%
Dockerfile 4.9%
HTML 2.1%
Other 0.2%