40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
"""Системная статистика: диск хранилища, CPU, RAM, аптайм."""
|
|
from __future__ import annotations
|
|
|
|
import shutil
|
|
import time
|
|
|
|
import psutil
|
|
|
|
from ..config import Config
|
|
|
|
_START = time.time()
|
|
|
|
|
|
def system_stats(config: Config) -> dict:
|
|
path = config.storage.path
|
|
try:
|
|
usage = shutil.disk_usage(path)
|
|
disk = {
|
|
"total_gb": round(usage.total / 1024 ** 3, 1),
|
|
"used_gb": round(usage.used / 1024 ** 3, 1),
|
|
"free_gb": round(usage.free / 1024 ** 3, 1),
|
|
"percent": round(usage.used / usage.total * 100, 1) if usage.total else 0,
|
|
}
|
|
except OSError:
|
|
disk = {"total_gb": 0, "used_gb": 0, "free_gb": 0, "percent": 0}
|
|
|
|
vm = psutil.virtual_memory()
|
|
return {
|
|
"uptime_s": int(time.time() - _START),
|
|
"cpu_percent": psutil.cpu_percent(interval=None),
|
|
"ram_percent": vm.percent,
|
|
"ram_used_gb": round(vm.used / 1024 ** 3, 1),
|
|
"ram_total_gb": round(vm.total / 1024 ** 3, 1),
|
|
"storage_path": path,
|
|
"disk": disk,
|
|
"quota_gb": config.storage.quota_gb,
|
|
"retention_days": config.storage.retention_days,
|
|
"segment_seconds": config.storage.segment_seconds,
|
|
}
|