diff --git a/lbry/blob/disk_space_manager.py b/lbry/blob/disk_space_manager.py index 3882d5d80..96053eca0 100644 --- a/lbry/blob/disk_space_manager.py +++ b/lbry/blob/disk_space_manager.py @@ -6,13 +6,14 @@ log = logging.getLogger(__name__) class DiskSpaceManager: - def __init__(self, config, db, blob_manager, cleaning_interval=30 * 60): + def __init__(self, config, db, blob_manager, cleaning_interval=30 * 60, analytics=None): self.config = config self.db = db self.blob_manager = blob_manager self.cleaning_interval = cleaning_interval self.running = False self.task = None + self.analytics = analytics async def get_space_used_bytes(self): return await self.db.get_stored_blob_disk_usage() @@ -21,10 +22,14 @@ class DiskSpaceManager: return int(await self.get_space_used_bytes()/1024.0/1024.0) async def clean(self): - if not self.config.blob_storage_limit: + space_used_bytes = await self.get_space_used_bytes() + storage_limit = self.config.blob_storage_limit*1024*1024 if self.config.blob_storage_limit else None + if self.analytics: + asyncio.create_task(self.analytics.send_disk_space_used(space_used_bytes, storage_limit)) + if not storage_limit: return 0 delete = [] - available = (self.config.blob_storage_limit*1024*1024) - await self.get_space_used_bytes() + available = storage_limit - space_used_bytes if available > 0: return 0 for blob_hash, file_size, _ in await self.db.get_stored_blobs(is_mine=False): diff --git a/lbry/extras/daemon/analytics.py b/lbry/extras/daemon/analytics.py index 77861dac8..868b14789 100644 --- a/lbry/extras/daemon/analytics.py +++ b/lbry/extras/daemon/analytics.py @@ -18,6 +18,7 @@ DOWNLOAD_STARTED = 'Download Started' DOWNLOAD_ERRORED = 'Download Errored' DOWNLOAD_FINISHED = 'Download Finished' HEARTBEAT = 'Heartbeat' +DISK_SPACE = 'Disk Space' CLAIM_ACTION = 'Claim Action' # publish/create/update/abandon NEW_CHANNEL = 'New Channel' CREDITS_SENT = 'Credits Sent' @@ -169,6 +170,14 @@ class AnalyticsManager: }) ) + async def send_disk_space_used(self, storage_used, storage_limit): + await self.track( + self._event(DISK_SPACE, { + 'used': storage_used, + 'limit': storage_limit, + }) + ) + async def send_server_startup(self): await self.track(self._event(SERVER_STARTUP)) diff --git a/lbry/extras/daemon/components.py b/lbry/extras/daemon/components.py index e38d4835f..8e32cf6c1 100644 --- a/lbry/extras/daemon/components.py +++ b/lbry/extras/daemon/components.py @@ -400,7 +400,10 @@ class DiskSpaceComponent(Component): async def start(self): db = self.component_manager.get_component(DATABASE_COMPONENT) blob_manager = self.component_manager.get_component(BLOB_COMPONENT) - self.disk_space_manager = DiskSpaceManager(self.conf, db, blob_manager) + self.disk_space_manager = DiskSpaceManager( + self.conf, db, blob_manager, + analytics=self.component_manager.analytics_manager + ) await self.disk_space_manager.start() async def stop(self):