forked from LBRYCommunity/lbry-sdk
add track_bandwidth
config setting to disable bandwidth usage in status
This commit is contained in:
parent
82f2ad21e1
commit
4f5a4d9ce0
3 changed files with 21 additions and 9 deletions
|
@ -86,6 +86,7 @@ class BlobManager:
|
||||||
to_add = await self.storage.sync_missing_blobs(in_blobfiles_dir)
|
to_add = await self.storage.sync_missing_blobs(in_blobfiles_dir)
|
||||||
if to_add:
|
if to_add:
|
||||||
self.completed_blob_hashes.update(to_add)
|
self.completed_blob_hashes.update(to_add)
|
||||||
|
if self.config.track_bandwidth:
|
||||||
self.connection_manager.start()
|
self.connection_manager.start()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -573,9 +573,9 @@ class Config(CLIConfig):
|
||||||
"Whether to share usage stats and diagnostic info with LBRY.", True,
|
"Whether to share usage stats and diagnostic info with LBRY.", True,
|
||||||
previous_names=['upload_log', 'upload_log', 'share_debug_info']
|
previous_names=['upload_log', 'upload_log', 'share_debug_info']
|
||||||
)
|
)
|
||||||
|
track_bandwidth = Toggle("Track bandwidth usage", True)
|
||||||
|
|
||||||
# media server
|
# media server
|
||||||
|
|
||||||
streaming_server = String('Host name and port to serve streaming media over range requests',
|
streaming_server = String('Host name and port to serve streaming media over range requests',
|
||||||
'localhost:5280', metavar='HOST:PORT')
|
'localhost:5280', metavar='HOST:PORT')
|
||||||
streaming_get = Toggle("Enable the /get endpoint for the streaming media server. "
|
streaming_get = Toggle("Enable the /get endpoint for the streaming media server. "
|
||||||
|
|
|
@ -19,7 +19,9 @@ class ConnectionManager:
|
||||||
self.outgoing_connected: typing.Set[str] = set()
|
self.outgoing_connected: typing.Set[str] = set()
|
||||||
self.outgoing: typing.DefaultDict[str, int] = collections.defaultdict(int)
|
self.outgoing: typing.DefaultDict[str, int] = collections.defaultdict(int)
|
||||||
self._status = {}
|
self._status = {}
|
||||||
|
self._total_sent = 0
|
||||||
|
self._total_received = 0
|
||||||
|
self._running = False
|
||||||
self._task: typing.Optional[asyncio.Task] = None
|
self._task: typing.Optional[asyncio.Task] = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -27,12 +29,15 @@ class ConnectionManager:
|
||||||
return self._status
|
return self._status
|
||||||
|
|
||||||
def sent_data(self, host_and_port: str, size: int):
|
def sent_data(self, host_and_port: str, size: int):
|
||||||
|
if self._running:
|
||||||
self.outgoing[host_and_port] += size
|
self.outgoing[host_and_port] += size
|
||||||
|
|
||||||
def received_data(self, host_and_port: str, size: int):
|
def received_data(self, host_and_port: str, size: int):
|
||||||
|
if self._running:
|
||||||
self.incoming[host_and_port] += size
|
self.incoming[host_and_port] += size
|
||||||
|
|
||||||
def connection_made(self, host_and_port: str):
|
def connection_made(self, host_and_port: str):
|
||||||
|
if self._running:
|
||||||
self.outgoing_connected.add(host_and_port)
|
self.outgoing_connected.add(host_and_port)
|
||||||
|
|
||||||
def connection_received(self, host_and_port: str):
|
def connection_received(self, host_and_port: str):
|
||||||
|
@ -40,20 +45,21 @@ class ConnectionManager:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def outgoing_connection_lost(self, host_and_port: str):
|
def outgoing_connection_lost(self, host_and_port: str):
|
||||||
if host_and_port in self.outgoing_connected:
|
if self._running and host_and_port in self.outgoing_connected:
|
||||||
self.outgoing_connected.remove(host_and_port)
|
self.outgoing_connected.remove(host_and_port)
|
||||||
|
|
||||||
def incoming_connection_lost(self, host_and_port: str):
|
def incoming_connection_lost(self, host_and_port: str):
|
||||||
if host_and_port in self.incoming_connected:
|
if self._running and host_and_port in self.incoming_connected:
|
||||||
self.incoming_connected.remove(host_and_port)
|
self.incoming_connected.remove(host_and_port)
|
||||||
|
|
||||||
async def _update(self):
|
async def _update(self):
|
||||||
|
|
||||||
self._status = {
|
self._status = {
|
||||||
'incoming_bps': {},
|
'incoming_bps': {},
|
||||||
'outgoing_bps': {},
|
'outgoing_bps': {},
|
||||||
'total_incoming_mbs': 0.0,
|
'total_incoming_mbs': 0.0,
|
||||||
'total_outgoing_mbs': 0.0,
|
'total_outgoing_mbs': 0.0,
|
||||||
|
'total_sent': self._total_sent,
|
||||||
|
'total_received': self._total_received,
|
||||||
'time': self.loop.time()
|
'time': self.loop.time()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,6 +79,9 @@ class ConnectionManager:
|
||||||
) / (now - last)) / 1000000.0
|
) / (now - last)) / 1000000.0
|
||||||
self._status['total_incoming_mbs'] = int(sum(list(self._status['incoming_bps'].values())
|
self._status['total_incoming_mbs'] = int(sum(list(self._status['incoming_bps'].values())
|
||||||
) / (now - last)) / 1000000.0
|
) / (now - last)) / 1000000.0
|
||||||
|
self._total_sent += sum(list(self._status['outgoing_bps'].values()))
|
||||||
|
self._total_received += sum(list(self._status['incoming_bps'].values()))
|
||||||
|
|
||||||
self._status['time'] = now
|
self._status['time'] = now
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
|
@ -84,7 +93,9 @@ class ConnectionManager:
|
||||||
self.incoming.clear()
|
self.incoming.clear()
|
||||||
self.incoming_connected.clear()
|
self.incoming_connected.clear()
|
||||||
self._status.clear()
|
self._status.clear()
|
||||||
|
self._running = False
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self.stop()
|
self.stop()
|
||||||
|
self._running = True
|
||||||
self._task = self.loop.create_task(self._update())
|
self._task = self.loop.create_task(self._update())
|
||||||
|
|
Loading…
Reference in a new issue