diff --git a/elstat/adapters.py b/elstat/adapters.py index 920fd77..c09f909 100644 --- a/elstat/adapters.py +++ b/elstat/adapters.py @@ -57,7 +57,7 @@ class PingAdapter(Adapter): else: latency = 0 - worker.log.info(f'{worker.name}: alive={alive} latency={latency}ms') + worker.log.info(f'alive={alive} latency={latency}ms') return cls._construct(alive, latency) @@ -79,8 +79,7 @@ class HttpAdapter(Adapter): latency = round((t_end - t_start) * 1000) - worker.log.info(f'{worker.name}: status={resp.status} ' - f'latency={latency}ms') + worker.log.info(f'status={resp.status} latency={latency}ms') if resp.status == 200: return cls._construct(True, latency) diff --git a/elstat/blueprints/streaming.py b/elstat/blueprints/streaming.py index 9422737..7332c86 100644 --- a/elstat/blueprints/streaming.py +++ b/elstat/blueprints/streaming.py @@ -107,5 +107,5 @@ async def streaming_ws(request, ws): await ws.ping() await asyncio.sleep(1) except websockets.exceptions.ConnectionClosed as wc: - log.warning(f'connection {ws.client_id} closed: {wc!r}') + log.warning(f'conn {ws.client_id} closed: {wc.code} {wc.reason!r}') request.app.manager.unsub_all(ws) diff --git a/elstat/manager.py b/elstat/manager.py index e9946ab..e41410f 100644 --- a/elstat/manager.py +++ b/elstat/manager.py @@ -137,10 +137,12 @@ class ServiceManager: pass log.info(f'unsubscribed {websocket.client_id} from {unsub}') + try: self._websockets.pop(websocket.client_id) except KeyError: pass + return unsub def _ws_send(self, websocket, data: Any): @@ -166,8 +168,13 @@ class ServiceManager: def _send(websocket): return self._raw_send(websocket, channel, data) - tasks = map(_send, websockets) - return list(tasks) + tasks = list(map(_send, websockets)) + + clients = len(tasks) + if clients: + log.info(f'Dispatching on {channel} to {clients} clients') + + return tasks def publish_incident(self, op: int, data: Any): ws_ids = self.subscribers['incidents']