From ffd83d8bbc62c9fa6b19eef7995041db8dfc1cff Mon Sep 17 00:00:00 2001 From: Mirko Milovanovic Date: Thu, 20 Feb 2025 22:48:25 +0100 Subject: [PATCH] feat: add environment variable documentation and update configurations for socket port in Docker setup --- README.md | 37 ++++++++++++------- docker-compose.yml | 1 + monolith-entrypoint.sh | 5 +++ telegraf.conf | 2 +- .../webpack/package-lock.json | 14 +++++++ .../webpack/package.json | 1 + .../webpack/webpack.config.js | 4 +- 7 files changed, 48 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index cf24789..aeaf94f 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,24 @@ The collector will start gathering WebRTC stats from the Selenium container and To stop the Docker containers run: `docker compose down -v` + +### 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 | + +Variables can be set in the `.env` 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`. @@ -71,6 +89,10 @@ The `docker-compose.yml` file defines the following services: 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. @@ -78,20 +100,7 @@ The `main.py` script sets up the Selenium WebDriver, collects WebRTC stats, and ### WebRTC Internals Exporter The `webrtc-internals-exporter` directory contains a Chromium extension that collects WebRTC stats from the browser. - -## Working Project Structure - -``` -peertube-collector/ -├── requirements.txt -├── telegraf.conf -├── docker-compose.yml -├── Dockerfile -├── main.py -├── .env -└── utils/ -└── webrtc-internals-exporter/ -``` +It uses Webpack to replace the server collector endpoint with an environment variable. # Credits diff --git a/docker-compose.yml b/docker-compose.yml index 570bc12..5536300 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -26,6 +26,7 @@ services: - DATABASE=${TELEGRAF_MONGODB_DATABASE:?"Database name is required"} - DSN=${TELEGRAF_MONGODB_DSN:?"DSN is required"} - HOSTNAME=${TELEGRAF_HOSTNAME:?"Hostname is required"} + - SOCKET_PORT=${SOCKET_PORT:?"Socket port is required"} healthcheck: test: ["CMD", "curl", "-f", "http://localhost:8080"] interval: 5s diff --git a/monolith-entrypoint.sh b/monolith-entrypoint.sh index e110778..e02b4f0 100644 --- a/monolith-entrypoint.sh +++ b/monolith-entrypoint.sh @@ -15,6 +15,11 @@ if [ -z "$TELEGRAF_MONGODB_DATABASE" ]; then exit 1 fi +if [ -z "$SOCKET_PORT" ]; then + echo "Error: SOCKET_PORT is not set" + exit 1 +fi + if [ -z "$VIDEO_URL" ]; then echo "Error: VIDEO_URL is not set" exit 1 diff --git a/telegraf.conf b/telegraf.conf index 15d282d..43b8b40 100644 --- a/telegraf.conf +++ b/telegraf.conf @@ -7,7 +7,7 @@ dedup_interval = "600s" [[inputs.socket_listener]] - service_address = "udp://:8094" + service_address = "udp://:${SOCKET_PORT}" data_format = "xpath_json" [[inputs.socket_listener.xpath]] metric_name = "'peertube'" diff --git a/webrtc-internals-exporter/webpack/package-lock.json b/webrtc-internals-exporter/webpack/package-lock.json index 0133ead..8ddcb77 100644 --- a/webrtc-internals-exporter/webpack/package-lock.json +++ b/webrtc-internals-exporter/webpack/package-lock.json @@ -12,6 +12,7 @@ "babel-loader": "^8.2.2", "clean-webpack-plugin": "^3.0.0", "copy-webpack-plugin": "^12.0.2", + "dotenv": "^16.4.7", "file-loader": "^6.2.0", "html-webpack-plugin": "^5.3.1", "mini-css-extract-plugin": "^1.6.0", @@ -3899,6 +3900,19 @@ "tslib": "^2.0.3" } }, + "node_modules/dotenv": { + "version": "16.4.7", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.7.tgz", + "integrity": "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/dunder-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", diff --git a/webrtc-internals-exporter/webpack/package.json b/webrtc-internals-exporter/webpack/package.json index 3b504b8..9ce239f 100644 --- a/webrtc-internals-exporter/webpack/package.json +++ b/webrtc-internals-exporter/webpack/package.json @@ -12,6 +12,7 @@ "babel-loader": "^8.2.2", "clean-webpack-plugin": "^3.0.0", "copy-webpack-plugin": "^12.0.2", + "dotenv": "^16.4.7", "file-loader": "^6.2.0", "html-webpack-plugin": "^5.3.1", "mini-css-extract-plugin": "^1.6.0", diff --git a/webrtc-internals-exporter/webpack/webpack.config.js b/webrtc-internals-exporter/webpack/webpack.config.js index d7ea04b..d9c4c33 100644 --- a/webrtc-internals-exporter/webpack/webpack.config.js +++ b/webrtc-internals-exporter/webpack/webpack.config.js @@ -1,5 +1,7 @@ const path = require('path'); const { EnvironmentPlugin } = require('webpack'); +const envPath = path.resolve(__dirname, '../../.env'); +const envConfig = require('dotenv').config({ path: envPath }).parsed; module.exports = (env) => { const url = env.URL || 'http://localhost'; @@ -25,7 +27,7 @@ module.exports = (env) => { }, plugins: [ new EnvironmentPlugin({ - WEBRTC_INTERNALS_EXPORTER_URL: url, + WEBRTC_INTERNALS_EXPORTER_URL: envConfig.WEBRTC_INTERNALS_EXPORTER_URL || url }), ], };