Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Storing records on remote s3 storage #6586

Draft
wants to merge 8 commits into
base: dev
Choose a base branch
from

Conversation

skrashevich
Copy link
Contributor

@skrashevich skrashevich commented May 23, 2023

Work in progress.

storage:
  s3: 
    enabled: true
    archive: false
    access_key_id: ****
    secret_access_key: *****
    bucket_name: frigate
    endpoint_url: http:https://192.168.88.171:9768
    path: "/"

@netlify
Copy link

netlify bot commented May 23, 2023

Deploy Preview for frigate-docs ready!

Name Link
🔨 Latest commit 33c8126
🔍 Latest deploy log https://app.netlify.com/sites/frigate-docs/deploys/646d2d14cf9c030008543025
😎 Deploy Preview https://deploy-preview-6586--frigate-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@blakeblackshear
Copy link
Owner

The VOD module needs to read the metadata of every segment file for recordings playback. It has a cache, but I imagine this would be incredibly slow if every recording file has to be fetched.

How long does it take to load an hour long m3u8 playlist when you have 24/7 recordings in all mode?

@skrashevich
Copy link
Contributor Author

nginx vod module has "remote" and "mapped" modes for work with non-local files

def __init__(self, config: FrigateConfig) -> None:
self.config = config
if self.config.storage.s3.enabled or self.config.storage.s3.archive:
if self.config.storage.s3.endpoint_url.startswith("http:https://"):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we use ssl by default here?

try:
total_size = 0
total_files = 0
for obj in self.s3_client.list_objects(Bucket=self.s3_bucket).get(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use list_objects_v2 and use pagination. Otherwise 1000+ objects will fail.

Something along those liines:

import boto3

def calculate_s3_bucket_size_and_file_count(bucket_name):
    s3 = boto3.client('s3')
    total_size = 0
    total_files = 0

    paginator = s3.get_paginator('list_objects_v2')
    for page in paginator.paginate(Bucket=bucket_name):
        for obj in page['Contents']:
            total_size += obj['Size']
            total_files += 1

    return total_size, total_files

bucket_name = 'my-bucket'  # Replace with your bucket name
total_size, total_files = calculate_s3_bucket_size_and_file_count(bucket_name)

print(f'Total size: {total_size / 1024**3} GB')  # Convert bytes to GB
print(f'Total number of files: {total_files}')

self.s3_client = session.create_client(
"s3",
aws_access_key_id=self.config.storage.s3.access_key_id,
aws_secret_access_key=self.config.storage.s3.secret_access_key,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are forcing the use of keys.

If config.storage.s3.access_key_id is NOT set, you should follow the default chain that allows users to use environment variable, ~/.aws/credentials etc.

See: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html

@javydekoning
Copy link

javydekoning commented May 28, 2023

@skrashevich this is a really awesome feature. I left a few comments for improvements.

I would disable s3 stats by default. Give users the option to enable it. On buckets with millions of objects this can become a slow operation due to its recursive nature. Also, I think you are gathering stats for the whole bucket.

What if a user uses "/frigate" as their base path. Wouldn't we want stats only for that path?

@blakeblackshear, I'm not an expert on VOD. That said, s3 is commonly used to store the main playlist and HLS files for VOD platforms. Hence, with the correct config wouldn't expect any performance issues.

@PovilasID
Copy link

I suggest adding a button next to a clip "Upload to S3" or option to "Upload only favorite clips". I personally do not have the bandwidth to upload all the vide that is captured but I would love to be able to backup specific certain clips.

@luckyycode
Copy link

any update?

@PovilasID
Copy link

There are couple of solution than you do yourself

  1. Clip upload. In HA notification script you can add uploads to s3 or telegram using rclone or curl.
  2. Rclone remote export. You can use rclone docker plugin to create volume that is actually a on remote server and specify it for exports, so that any time you export a clip it will get saved to remote server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants