mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
Refactor storage stats calculation to use powers of 2 for more accurate values (#6765)
* "Refactor storage stats calculation to use powers of 2 for more accurate values" * replace 1000000 to 2^20 * Refactor storage unit size display to use binary prefixes This commit updates the display of storage unit sizes in both the camera storage stats and the Storage component in the web UI to use binary prefixes (MiB and GiB) instead of decimal prefixes (MB and GB). This provides more accurate and consistent representation of storage sizes
This commit is contained in:
parent
b359ff1b8e
commit
dfd574beeb
@ -429,7 +429,7 @@ class FrigateApp:
|
|||||||
self.frigate_watchdog.start()
|
self.frigate_watchdog.start()
|
||||||
|
|
||||||
def check_shm(self) -> None:
|
def check_shm(self) -> None:
|
||||||
available_shm = round(shutil.disk_usage("/dev/shm").total / 1000000, 1)
|
available_shm = round(shutil.disk_usage("/dev/shm").total / pow(2, 20), 1)
|
||||||
min_req_shm = 30
|
min_req_shm = 30
|
||||||
|
|
||||||
for _, camera in self.config.cameras.items():
|
for _, camera in self.config.cameras.items():
|
||||||
|
@ -326,7 +326,7 @@ class RecordingMaintainer(threading.Thread):
|
|||||||
# get the segment size of the cache file
|
# get the segment size of the cache file
|
||||||
# file without faststart is same size
|
# file without faststart is same size
|
||||||
segment_size = round(
|
segment_size = round(
|
||||||
float(os.path.getsize(cache_path)) / 1000000, 1
|
float(os.path.getsize(cache_path)) / pow(2, 20), 1
|
||||||
)
|
)
|
||||||
except OSError:
|
except OSError:
|
||||||
segment_size = 0
|
segment_size = 0
|
||||||
|
@ -286,9 +286,9 @@ def stats_snapshot(
|
|||||||
stats["service"]["storage"][path] = {}
|
stats["service"]["storage"][path] = {}
|
||||||
|
|
||||||
stats["service"]["storage"][path] = {
|
stats["service"]["storage"][path] = {
|
||||||
"total": round(storage_stats.total / 1000000, 1),
|
"total": round(storage_stats.total / pow(2, 20), 1),
|
||||||
"used": round(storage_stats.used / 1000000, 1),
|
"used": round(storage_stats.used / pow(2, 20), 1),
|
||||||
"free": round(storage_stats.free / 1000000, 1),
|
"free": round(storage_stats.free / pow(2, 20), 1),
|
||||||
"mount_type": get_fs_type(path),
|
"mount_type": get_fs_type(path),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ class StorageMaintainer(threading.Thread):
|
|||||||
bandwidth = 0
|
bandwidth = 0
|
||||||
|
|
||||||
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} MiB/hr.")
|
||||||
|
|
||||||
def calculate_camera_usages(self) -> dict[str, dict]:
|
def calculate_camera_usages(self) -> dict[str, dict]:
|
||||||
"""Calculate the storage usage of each camera."""
|
"""Calculate the storage usage of each camera."""
|
||||||
@ -85,7 +85,7 @@ class StorageMaintainer(threading.Thread):
|
|||||||
hourly_bandwidth = sum(
|
hourly_bandwidth = sum(
|
||||||
[b["bandwidth"] for b in self.camera_storage_stats.values()]
|
[b["bandwidth"] for b in self.camera_storage_stats.values()]
|
||||||
)
|
)
|
||||||
remaining_storage = round(shutil.disk_usage(RECORD_DIR).free / 1000000, 1)
|
remaining_storage = round(shutil.disk_usage(RECORD_DIR).free / pow(2, 20), 1)
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"Storage cleanup check: {hourly_bandwidth} hourly with remaining storage: {remaining_storage}."
|
f"Storage cleanup check: {hourly_bandwidth} hourly with remaining storage: {remaining_storage}."
|
||||||
)
|
)
|
||||||
|
@ -26,9 +26,9 @@ export default function Storage() {
|
|||||||
|
|
||||||
const getUnitSize = (MB) => {
|
const getUnitSize = (MB) => {
|
||||||
if (isNaN(MB) || MB < 0) return 'Invalid number';
|
if (isNaN(MB) || MB < 0) return 'Invalid number';
|
||||||
if (MB < 1024) return `${MB} MB`;
|
if (MB < 1024) return `${MB} MiB`;
|
||||||
|
|
||||||
return `${(MB / 1024).toFixed(2)} GB`;
|
return `${(MB / 1024).toFixed(2)} GiB`;
|
||||||
};
|
};
|
||||||
|
|
||||||
let storage_usage;
|
let storage_usage;
|
||||||
|
Loading…
Reference in New Issue
Block a user