Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions modules/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import uuid
import json
import time

from pytubefix import YouTube

Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions modules/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down