Skip to content

Commit

Permalink
Show available disk space in stats
Browse files Browse the repository at this point in the history
  • Loading branch information
jordimas committed Oct 18, 2024
1 parent 2eef98c commit acee93c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
24 changes: 17 additions & 7 deletions transcribe-batch/processedfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,30 @@ def get_num_of_files_stored(directory=PROCESSED):
files = ProcessedFiles._find_files(directory, "*")
return len(files)

def _get_human_readable_size(size):
GB_IN_BYTES = 1024**3
if size > GB_IN_BYTES:
gbs = size / GB_IN_BYTES
text = f"{gbs:.2f} GB"
else:
text = f"{size} bytes"

return text

def get_num_of_files_stored_size(directory=PROCESSED):
files = ProcessedFiles._find_files(directory, "*")
total_size = 0
for _file in files:
total_size += os.stat(_file).st_size

GB_IN_BYTES = 1024 * 1024 * 1024
if total_size > GB_IN_BYTES:
gbs = total_size / GB_IN_BYTES
size = f"{gbs:.2f} GB"
else:
size = f"{total_size} bytes"
return ProcessedFiles._get_human_readable_size(total_size)

def get_free_space_in_directory(directory=PROCESSED):
statvfs = os.statvfs(directory)

return size
# Available blocks * block size gives the available space in bytes
free_space_bytes = statvfs.f_frsize * statvfs.f_bavail
return ProcessedFiles._get_human_readable_size(free_space_bytes)

def purge_files(days, directory=PROCESSED):
HOURS_DAY = 24
Expand Down
1 change: 1 addition & 0 deletions transcribe-service/transcribe-service.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def stats():

result["files_stored"] = ProcessedFiles.get_num_of_files_stored()
result["files_stored_size"] = ProcessedFiles.get_num_of_files_stored_size()
result["free_storage_space"] = ProcessedFiles.get_free_space_in_directory()
queue["items"] = len(records)
queue["who"] = print_who
result["queue"] = queue
Expand Down

0 comments on commit acee93c

Please sign in to comment.