mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-02-14 00:17:05 +01:00
add disk usage to stats
This commit is contained in:
parent
163025c1f2
commit
4f5d4e36b7
@ -2,8 +2,11 @@ import json
|
|||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
import psutil
|
||||||
|
import shutil
|
||||||
|
|
||||||
from frigate.config import FrigateConfig
|
from frigate.config import FrigateConfig
|
||||||
|
from frigate.const import RECORD_DIR, CLIPS_DIR, CACHE_DIR
|
||||||
from frigate.version import VERSION
|
from frigate.version import VERSION
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -16,6 +19,15 @@ def stats_init(camera_metrics, detectors):
|
|||||||
}
|
}
|
||||||
return stats_tracking
|
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):
|
def stats_snapshot(stats_tracking):
|
||||||
camera_metrics = stats_tracking['camera_metrics']
|
camera_metrics = stats_tracking['camera_metrics']
|
||||||
stats = {}
|
stats = {}
|
||||||
@ -44,9 +56,19 @@ def stats_snapshot(stats_tracking):
|
|||||||
|
|
||||||
stats['service'] = {
|
stats['service'] = {
|
||||||
'uptime': (int(time.time()) - stats_tracking['started']),
|
'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
|
return stats
|
||||||
|
|
||||||
class StatsEmitter(threading.Thread):
|
class StatsEmitter(threading.Thread):
|
||||||
|
Loading…
Reference in New Issue
Block a user