Add convenience functions, update Docker setup, and integrate Webpack for building WebRTC internals exporter #3

Merged
kobim merged 4 commits from feature/webpack-monolith-image-parametrized-options into main 2025-02-21 11:21:14 +00:00
20 changed files with 9772 additions and 72 deletions
Showing only changes of commit e1dc7bc5c9 - Show all commits

View File

@@ -10,19 +10,12 @@ peertube-collector is a project designed to collect and analyze WebRTC statistic
- Docker Engine Community version is required. To install Docker CE, follow the official [install instructions](https://docs.docker.com/engine/install/).
### Ports:
#### Docker to Host:
- 4444 (Selenium)
Ports can be opened in the host machine's firewall with:
```sh
ufw allow from 172.100.0.0/16 to any port 4444
```
#### External (OPTIONAL):
These ports are actively used by selenium and the collector services. By defaut they should not be blocked by the firewall, but if so, they can be opened in the host machine's firewall.
#### External (OPTIONAL PROBABLY NOT NEEDED!!!):
These ports are actively used by selenium and the collector services.
- 50000:60000/udp (WebRTC)
- Needed for WebRTC NAT traversal, otherwise the browser will not connect to any peer.
- 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)
@@ -31,21 +24,18 @@ Ports can be opened in the host machine's firewall with:
ufw allow 50000:60000/udp
ufw allow 27107/tcp
```
## Setup
## Setup with Docker Compose
1. Clone the repository:
```sh
git clone <repository-url>
cd peertube-collector
```
2. Create and configure the environment file based on the `.env.example` file:
```sh
cp .env.example .env
```
3. Ajust the firewall settings to allow the necessary ports if needed
4. Start the Docker containers:
```sh
docker compose up --abort-on-container-failure
@@ -55,23 +45,40 @@ The collector will start gathering WebRTC stats from the Selenium container and
To stop the Docker containers run: `docker compose down -v`
### Setup with Monolithic image:
1. Clone the repository:
```sh
git clone <repository-url>
cd peertube-collector
```
2. Create and configure the environment file based on the `.env.example` file:
```sh
cp .env.example .env
```
3. Ajust the firewall settings to allow the necessary ports if needed
4. Start the Docker container:
```sh
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:%40z%5EVFhN7q%25vzit@tube.kobim.cloud:27107/?authSource=statistics` | DSN for the MongoDB service |
| `TELEGRAF_MONGODB_DATABASE` | telegraf | Database name to use for MongoDB |
| `VIDEO_URL` | collector | `https://tube.kobim.cloud/w/iN2T8PmbSb4HJTDA2rV3sg` | 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 | `os.path.abspath(os.path.join(os.path.dirname(__file__), 'webrtc-internals-exporter'))` | Path for WebRTC internals exporter extension |
| `WEBRTC_INTERNALS_EXPORTER_URL` | WebRTC extension | `http://localhost:9092` | Collector URL for the WebRTC internals exporter extension |
| 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](http://localhost:7900/?autoconnect=1&resize=scale&password=secret) to monitor the Selenium container. The password is `secret`.

View File

@@ -230,7 +230,12 @@ if __name__ == '__main__':
setupStats(driver, url)
socket_url = firstValid(args.socket_url, os.getenv('SOCKET_URL'), default='localhost')
socket_port = firstValid(args.socket_port, os.getenv('SOCKET_PORT'), default=8094)
try:
socket_port = int(firstValid(args.socket_port, os.getenv('SOCKET_PORT'), default=8094))
except ValueError:
logger.error('Invalid socket port provided. Exiting.')
raise SystemExit(1)
logger.info('Starting server collector.')
httpd = HTTPServer(('', 9092), partial(Handler, downloadStats, driver, logger, socket_url, socket_port))
httpd.serve_forever()