diff --git a/modules/cache.py b/modules/cache.py index 326d1d8..706a8bd 100644 --- a/modules/cache.py +++ b/modules/cache.py @@ -4,6 +4,7 @@ import os import uuid import json +import time from pytubefix import YouTube @@ -58,8 +59,10 @@ def add(self, url: str): MetricsHandler.cache_size.set(len(self.video_id_to_path)) MetricsHandler.cache_size_bytes.set(self.current_size_bytes) video_file_name = video.default_filename + start_time = time.time() with MetricsHandler.download_time.time(): video.download(self.file_path) + end_time = time.time() MetricsHandler.data_downloaded.inc(video.filesize) MetricsHandler.video_download_count.inc() video_id = self.get_video_id(url) @@ -80,6 +83,9 @@ def add(self, url: str): self.current_size_bytes += video_info.size_bytes MetricsHandler.cache_size.set(len(self.video_id_to_path)) MetricsHandler.cache_size_bytes.set(self.current_size_bytes) + #download rate are currently listed in bytes / second + download_rate = (video.filesize / (end_time-start_time)) + MetricsHandler.download_rate.observe(download_rate) def find(self, video_id: str): if video_id in self.video_id_to_path: diff --git a/modules/metrics.py b/modules/metrics.py index 20fbd8c..ae99988 100644 --- a/modules/metrics.py +++ b/modules/metrics.py @@ -30,6 +30,12 @@ class Metrics(enum.Enum): prometheus_client.Summary, ) + DOWNLOAD_RATE = ( + "download_rate", + "The rate of downloading videos in bytes per seconds", + prometheus_client.Histogram, + ) + DATA_DOWNLOADED = ( "data_downloaded", "Total video data downloaded in bytes",