浏览代码

add disk usage to stats

Blake Blackshear 4 年之前
父节点
当前提交
4f5d4e36b7
共有 1 个文件被更改,包括 23 次插入1 次删除
  1. 23 1
      frigate/stats.py

+ 23 - 1
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):