mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-05 18:55:23 +03:00
Add S3 storage bucket stats to service stats snapshot
This commit is contained in:
parent
1dc78c87fc
commit
502baec38a
@ -18,6 +18,7 @@ from frigate.util import get_amd_gpu_stats, get_intel_gpu_stats, get_nvidia_gpu_
|
|||||||
from frigate.version import VERSION
|
from frigate.version import VERSION
|
||||||
from frigate.util import get_cpu_stats, get_bandwidth_stats
|
from frigate.util import get_cpu_stats, get_bandwidth_stats
|
||||||
from frigate.object_detection import ObjectDetectProcess
|
from frigate.object_detection import ObjectDetectProcess
|
||||||
|
from frigate.storage import StorageS3
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -274,6 +275,10 @@ def stats_snapshot(
|
|||||||
"mount_type": get_fs_type(path),
|
"mount_type": get_fs_type(path),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.storage.s3.enabled or config.storage.s3.archive:
|
||||||
|
s3 = StorageS3(config)
|
||||||
|
stats["service"]["storage"]["s3"] = s3.get_bucket_stats()
|
||||||
|
|
||||||
stats["processes"] = {}
|
stats["processes"] = {}
|
||||||
for name, pid in stats_tracking["processes"].items():
|
for name, pid in stats_tracking["processes"].items():
|
||||||
stats["processes"][name] = {
|
stats["processes"][name] = {
|
||||||
|
|||||||
@ -43,7 +43,7 @@ class StorageS3:
|
|||||||
aws_access_key_id=self.config.storage.s3.access_key_id,
|
aws_access_key_id=self.config.storage.s3.access_key_id,
|
||||||
aws_secret_access_key=self.config.storage.s3.secret_access_key,
|
aws_secret_access_key=self.config.storage.s3.secret_access_key,
|
||||||
endpoint_url=self.config.storage.s3.endpoint_url,
|
endpoint_url=self.config.storage.s3.endpoint_url,
|
||||||
config=Config(signature_version=UNSIGNED),
|
config=Config(),
|
||||||
)
|
)
|
||||||
except (BotoCoreError, ClientError) as error:
|
except (BotoCoreError, ClientError) as error:
|
||||||
logger.error(f"Failed to create S3 client: {error}")
|
logger.error(f"Failed to create S3 client: {error}")
|
||||||
@ -98,6 +98,23 @@ class StorageS3:
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def get_bucket_stats(self):
|
||||||
|
try:
|
||||||
|
total_size = 0
|
||||||
|
total_files = 0
|
||||||
|
for obj in self.s3_client.list_objects(Bucket=self.s3_bucket).get(
|
||||||
|
"Contents", []
|
||||||
|
):
|
||||||
|
total_size += obj["Size"]
|
||||||
|
total_files += 1
|
||||||
|
|
||||||
|
total_size_gb = total_size / (1024**3) # Convert bytes to gigabytes
|
||||||
|
return {"total_files": total_files, "total_size_gb": total_size_gb}
|
||||||
|
|
||||||
|
except ClientError as e:
|
||||||
|
print(f"Error getting bucket stats: {e}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class StorageMaintainer(threading.Thread):
|
class StorageMaintainer(threading.Thread):
|
||||||
"""Maintain frigates recording storage."""
|
"""Maintain frigates recording storage."""
|
||||||
|
|||||||
@ -48,6 +48,12 @@ export default function Storage() {
|
|||||||
<Td>{getUnitSize(service['storage']['/media/frigate/clips']['used'])}</Td>
|
<Td>{getUnitSize(service['storage']['/media/frigate/clips']['used'])}</Td>
|
||||||
<Td>{getUnitSize(service['storage']['/media/frigate/clips']['total'])}</Td>
|
<Td>{getUnitSize(service['storage']['/media/frigate/clips']['total'])}</Td>
|
||||||
</Tr>
|
</Tr>
|
||||||
|
{service['storage']['s3'] ? (
|
||||||
|
<Tr>
|
||||||
|
<Td>S3</Td>
|
||||||
|
<Td>{getUnitSize(service['storage']['s3']['total_size_gb'])}</Td>
|
||||||
|
<Td>{service['storage']['s3']['total_files']} files</Td>
|
||||||
|
</Tr> ) : null}
|
||||||
</Fragment>
|
</Fragment>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@ -58,6 +64,12 @@ export default function Storage() {
|
|||||||
<Td>{getUnitSize(service['storage']['/media/frigate/recordings']['used'])}</Td>
|
<Td>{getUnitSize(service['storage']['/media/frigate/recordings']['used'])}</Td>
|
||||||
<Td>{getUnitSize(service['storage']['/media/frigate/recordings']['total'])}</Td>
|
<Td>{getUnitSize(service['storage']['/media/frigate/recordings']['total'])}</Td>
|
||||||
</Tr>
|
</Tr>
|
||||||
|
{service['storage']['s3'] ? (
|
||||||
|
<Tr>
|
||||||
|
<Td>S3</Td>
|
||||||
|
<Td>{getUnitSize(service['storage']['s3']['total_size_gb'])}</Td>
|
||||||
|
<Td>{service['storage']['s3']['total_files']} files</Td>
|
||||||
|
</Tr> ) : null}
|
||||||
</Fragment>
|
</Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user