Skip to content

Commit f84a84e

Browse files
committed
added metric for video download-rate
1 parent 07ad43b commit f84a84e

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

modules/cache.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import uuid
66
import json
7+
import time
78

89
from pytubefix import YouTube
910

@@ -58,8 +59,10 @@ def add(self, url: str):
5859
MetricsHandler.cache_size.set(len(self.video_id_to_path))
5960
MetricsHandler.cache_size_bytes.set(self.current_size_bytes)
6061
video_file_name = video.default_filename
62+
start_time = time.time()
6163
with MetricsHandler.download_time.time():
6264
video.download(self.file_path)
65+
end_time = time.time()
6366
MetricsHandler.data_downloaded.inc(video.filesize)
6467
MetricsHandler.video_download_count.inc()
6568
video_id = self.get_video_id(url)
@@ -80,6 +83,9 @@ def add(self, url: str):
8083
self.current_size_bytes += video_info.size_bytes
8184
MetricsHandler.cache_size.set(len(self.video_id_to_path))
8285
MetricsHandler.cache_size_bytes.set(self.current_size_bytes)
86+
#download rate are currently listed in bytes / second
87+
download_rate = (video.filesize / (end_time-start_time))
88+
MetricsHandler.download_rate.set(download_rate)
8389

8490
def find(self, video_id: str):
8591
if video_id in self.video_id_to_path:

modules/metrics.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ class Metrics(enum.Enum):
3030
prometheus_client.Summary,
3131
)
3232

33+
DOWNLOAD_RATE = (
34+
"download_rate",
35+
"The rate of downloading videos in bytes per seconds",
36+
prometheus_client.Gauge,
37+
)
38+
3339
DATA_DOWNLOADED = (
3440
"data_downloaded",
3541
"Total video data downloaded in bytes",

0 commit comments

Comments
 (0)