mirror of
https://github.com/MOIS3Y/logs-collector.git
synced 2025-09-13 05:03:01 +02:00
Modify: settings - add DATA_DIR logs_collector storage_info use DATA_DIR as storage root
This commit is contained in:
@@ -66,3 +66,4 @@ class StorageInfoSerializer(serializers.Serializer):
|
||||
used = serializers.IntegerField(read_only=True)
|
||||
free = serializers.IntegerField(read_only=True)
|
||||
used_percent = serializers.IntegerField(read_only=True)
|
||||
status = serializers.CharField(read_only=True)
|
||||
|
@@ -171,4 +171,4 @@ class StorageInfo(views.APIView):
|
||||
summary='Show storage space in bytes'
|
||||
)
|
||||
def get(self, request):
|
||||
return Response(get_mount_fs_info(settings.MEDIA_ROOT))
|
||||
return Response(get_mount_fs_info(settings.DATA_DIR))
|
||||
|
@@ -13,4 +13,4 @@ def metadata(request):
|
||||
|
||||
|
||||
def storage_info(request):
|
||||
return {'storage': get_mount_fs_info(settings.MEDIA_ROOT)}
|
||||
return {'storage': get_mount_fs_info(settings.DATA_DIR)}
|
||||
|
@@ -1,7 +1,8 @@
|
||||
import shutil
|
||||
import pathlib
|
||||
|
||||
|
||||
def logs_dir_path(instance, filename):
|
||||
def logs_dir_path(instance, filename: str) -> str:
|
||||
"""
|
||||
file will be uploaded to
|
||||
MEDIA_ROOT/view/<filename>
|
||||
@@ -30,9 +31,31 @@ def sizify(value: int) -> str:
|
||||
return f'{round(value, 1)} {ext}'
|
||||
|
||||
|
||||
def get_mount_fs_info(path):
|
||||
mount_info = shutil.disk_usage(path)._asdict()
|
||||
mount_info['used_percent'] = round(
|
||||
mount_info['used'] / mount_info['total'] * 100
|
||||
)
|
||||
def get_mount_fs_info(path: type[pathlib.PosixPath]) -> dict:
|
||||
"""
|
||||
Get directory information for storing uploaded files.
|
||||
Includes information total/used/free space on mount device
|
||||
|
||||
Args:
|
||||
path (pathlib.PosixPath): path to storage dir
|
||||
|
||||
Returns:
|
||||
dict: storage mount info
|
||||
"""
|
||||
mount_info: dict = {}
|
||||
try:
|
||||
mount_info = shutil.disk_usage(path)._asdict()
|
||||
mount_info['used_percent'] = round(
|
||||
mount_info['used'] / mount_info['total'] * 100,
|
||||
)
|
||||
mount_info['status'] = 'mount'
|
||||
except Exception as error: # expected FileNotFoundError
|
||||
mount_info = {
|
||||
'total': 0,
|
||||
'used': 0,
|
||||
'free': 0,
|
||||
'used_percent': 0,
|
||||
'status': 'error',
|
||||
'traceback': f'{error}'
|
||||
}
|
||||
return mount_info
|
||||
|
Reference in New Issue
Block a user