From fb765920b44a8cbdbf519c6598419d6dabf909d3 Mon Sep 17 00:00:00 2001 From: Mirko Milovanovic Date: Wed, 5 Feb 2025 16:16:57 +0100 Subject: [PATCH] feat: add environment variable support and update README instructions --- .gitignore | 1 + README.md | 8 +++++++- docker-compose.yml | 6 ++++++ example.env | 8 ++++++++ main.py | 7 ++++++- telegraf.conf | 15 ++++++++------- webrtc-internals-exporter/background.js | 3 ++- 7 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 example.env diff --git a/.gitignore b/.gitignore index ba80d82..d9058a7 100644 --- a/.gitignore +++ b/.gitignore @@ -292,6 +292,7 @@ TSWLatexianTemp* .ipynb_checkpoints/ env/ +.env __pycache__/ test/ venv/ diff --git a/README.md b/README.md index 371fd75..7217f3d 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,13 @@ peertube-collector/ cd peertube-collector ``` -2. Build and start the Docker containers: +2. Create and configure the environment file based on the `.env.example` file: + ```sh + cp .env.example .env + ``` + + +3. Build and start the Docker containers: ```sh docker-compose up --build ``` diff --git a/docker-compose.yml b/docker-compose.yml index 7e0e577..2beeb79 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,6 +21,10 @@ services: image: telegraf:1.33.1 volumes: - ./telegraf.conf:/etc/telegraf/telegraf.conf:ro + environment: + - DATABASE=${TELEGRAF_MONGODB_DATABASE:?"Database name is required"} + - DSN=${TELEGRAF_MONGODB_DSN:?"DSN is required"} + - HOSTNAME=${TELEGRAF_HOSTNAME:?"Hostname is required"} networks: - backend @@ -34,6 +38,8 @@ services: condition: service_healthy telegraf: condition: service_started + environment: + - VIDEO_URL=${VIDEO_URL:?"Video URL is required"} networks: - backend diff --git a/example.env b/example.env new file mode 100644 index 0000000..479ef0b --- /dev/null +++ b/example.env @@ -0,0 +1,8 @@ +# User defined hostname persisted across all sessions, used to keep track of the same user +TELEGRAF_HOSTNAME= +# MongoDB connection string +TELEGRAF_MONGODB_DSN= +# MongoDB database name to store the data +TELEGRAF_MONGODB_DATABASE= +# URL of the video to be analyzed +VIDEO_URL= \ No newline at end of file diff --git a/main.py b/main.py index 0c3ae52..d3e3b19 100644 --- a/main.py +++ b/main.py @@ -183,7 +183,12 @@ if __name__ == '__main__': signal.signal(signal.SIGINT, lambda signum, frame: interrupt_handler(signum, driver)) - setupStats(driver, "https://tube.kobim.cloud/w/iN2T8PmbSb4HJTDA2rV3sg") + url = os.getenv('VIDEO_URL') + if url is None: + logger.error('VIDEO_URL environment variable is not set.') + raise SystemExit(1) + + setupStats(driver, url) logger.log(logging.INFO, 'Starting server collector.') httpd = HTTPServer(('collector', 9092), partial(Handler, downloadStats, driver, logger)) diff --git a/telegraf.conf b/telegraf.conf index 4ce5353..d4e3a7f 100644 --- a/telegraf.conf +++ b/telegraf.conf @@ -1,3 +1,7 @@ +[agent] + hostname = "${HOSTNAME}" + omit_hostname = false + [[processors.dedup]] dedup_interval = "600s" @@ -14,8 +18,7 @@ [inputs.socket_listener.xpath.tags] url = "url" session = "session" - #id = ?? - #state = ?? + host = "host" [inputs.socket_listener.xpath.fields] player = "player" @@ -26,8 +29,6 @@ data_format = "json" [[outputs.mongodb]] - dsn = "mongodb://stats_user:%40z%5EVFhN7q%25vzit@192.168.86.120:27017/?authSource=statistics" - database = "statistics" - granularity = "seconds" - -# docker run --rm -v .\peertube\statnerd\telegraf.conf:/etc/telegraf/telegraf.conf:ro -p 8094:8094/udp telegraf \ No newline at end of file + dsn = "${DSN}" + database = "${DATABASE}" + granularity = "seconds" \ No newline at end of file diff --git a/webrtc-internals-exporter/background.js b/webrtc-internals-exporter/background.js index 79fea75..71ccc94 100644 --- a/webrtc-internals-exporter/background.js +++ b/webrtc-internals-exporter/background.js @@ -16,7 +16,8 @@ const DEFAULT_OPTIONS = { gzip: false, job: "webrtc-internals-exporter", enabledOrigins: { - "https://tube.kobim.cloud": true, + "http://*/*": true, + "https://*/*": true, }, enabledStats: ["data-channel", "local-candidate", "remote-candidate"] };