mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-03 17:55:21 +03:00
Rewrite storage logic to use storage maintainer and segment sizes
This commit is contained in:
parent
60ec0d9e58
commit
c9eeb714ce
@ -694,12 +694,19 @@ def get_recordings_storage_usage():
|
|||||||
recording_stats = stats_snapshot(current_app.stats_tracking)["service"]["storage"][
|
recording_stats = stats_snapshot(current_app.stats_tracking)["service"]["storage"][
|
||||||
RECORD_DIR
|
RECORD_DIR
|
||||||
]
|
]
|
||||||
total_bytes = recording_stats["total"]
|
total_mb = recording_stats["total"]
|
||||||
storage = {"cameras": {}, "total": total_bytes}
|
|
||||||
storage[camera_name] = camera_bytes
|
|
||||||
total_bytes += camera_bytes
|
|
||||||
|
|
||||||
return jsonify(storage)
|
camera_usages: dict[
|
||||||
|
str, dict
|
||||||
|
] = current_app.storage_maintainer.calculate_camera_usages()
|
||||||
|
camera_usages["max"] = total_mb
|
||||||
|
|
||||||
|
for camera_name in camera_usages.keys():
|
||||||
|
camera_usages[camera_name]["usage_percent"] = (
|
||||||
|
camera_usages[camera_name]["usage"] / total_mb
|
||||||
|
)
|
||||||
|
|
||||||
|
return jsonify(camera_usages)
|
||||||
|
|
||||||
|
|
||||||
# return hourly summary for recordings of camera
|
# return hourly summary for recordings of camera
|
||||||
|
|||||||
@ -60,6 +60,23 @@ class StorageMaintainer(threading.Thread):
|
|||||||
self.camera_storage_stats[camera]["bandwidth"] = bandwidth
|
self.camera_storage_stats[camera]["bandwidth"] = bandwidth
|
||||||
logger.debug(f"{camera} has a bandwidth of {bandwidth} MB/hr.")
|
logger.debug(f"{camera} has a bandwidth of {bandwidth} MB/hr.")
|
||||||
|
|
||||||
|
def calculate_camera_usages(self) -> dict[str, dict]:
|
||||||
|
"""Calculate the storage usage of each camera."""
|
||||||
|
usages: dict[str, dict] = {}
|
||||||
|
total_storage = 0
|
||||||
|
|
||||||
|
for camera in self.config.cameras.keys():
|
||||||
|
camera_storage = (
|
||||||
|
Recordings.select(fn.SUM(Recordings.segment_size))
|
||||||
|
.where(Recordings.camera == camera, Recordings.segment_size != 0)
|
||||||
|
.scalar()
|
||||||
|
)
|
||||||
|
total_storage += camera_storage
|
||||||
|
usages[camera] = {"usage": camera_storage}
|
||||||
|
|
||||||
|
usages["total"] = {"usage": total_storage}
|
||||||
|
return usages
|
||||||
|
|
||||||
def check_storage_needs_cleanup(self) -> bool:
|
def check_storage_needs_cleanup(self) -> bool:
|
||||||
"""Return if storage needs cleanup."""
|
"""Return if storage needs cleanup."""
|
||||||
# currently runs cleanup if less than 1 hour of space is left
|
# currently runs cleanup if less than 1 hour of space is left
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user