File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44import os
55import uuid
66import json
7+ import time
78
89from 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 :
Original file line number Diff line number Diff 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" ,
You can’t perform that action at this time.
0 commit comments