From 4f5d4e36b72be0fdb76b3ab2e032e71b4a6e2f0e Mon Sep 17 00:00:00 2001 From: Blake Blackshear Date: Wed, 3 Feb 2021 06:36:13 -0600 Subject: [PATCH] add disk usage to stats --- frigate/stats.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/frigate/stats.py b/frigate/stats.py index ca722f6df..9d03dcd9b 100644 --- a/frigate/stats.py +++ b/frigate/stats.py @@ -2,8 +2,11 @@ import json import logging import threading import time +import psutil +import shutil from frigate.config import FrigateConfig +from frigate.const import RECORD_DIR, CLIPS_DIR, CACHE_DIR from frigate.version import VERSION logger = logging.getLogger(__name__) @@ -16,6 +19,15 @@ def stats_init(camera_metrics, detectors): } return stats_tracking +def get_fs_type(path): + bestMatch = "" + fsType = "" + for part in psutil.disk_partitions(all=True): + if path.startswith(part.mountpoint) and len(bestMatch) < len(part.mountpoint): + fsType = part.fstype + bestMatch = part.mountpoint + return fsType + def stats_snapshot(stats_tracking): camera_metrics = stats_tracking['camera_metrics'] stats = {} @@ -44,9 +56,19 @@ def stats_snapshot(stats_tracking): stats['service'] = { 'uptime': (int(time.time()) - stats_tracking['started']), - 'version': VERSION + 'version': VERSION, + 'storage': {} } + for path in [RECORD_DIR, CLIPS_DIR, CACHE_DIR, "/dev/shm"]: + storage_stats = shutil.disk_usage(path) + stats['service']['storage'][path] = { + 'total': round(storage_stats.total/1000000, 1), + 'used': round(storage_stats.used/1000000, 1), + 'free': round(storage_stats.free/1000000, 1), + 'mount_type': get_fs_type(path) + } + return stats class StatsEmitter(threading.Thread):