refactor: heartbeat spamming log
This commit is contained in:
parent
aa10d5a55c
commit
6ec10682c0
1 changed files with 20 additions and 7 deletions
|
@ -39,6 +39,8 @@ class WebSocketHandler:
|
||||||
self.connected = False
|
self.connected = False
|
||||||
self._heartbeat_task: Optional[asyncio.Task] = None
|
self._heartbeat_task: Optional[asyncio.Task] = None
|
||||||
self._message_task: Optional[asyncio.Task] = None
|
self._message_task: Optional[asyncio.Task] = None
|
||||||
|
self._heartbeat_count = 0
|
||||||
|
self._last_processed_models: set = set() # Cache of last processed model IDs
|
||||||
|
|
||||||
async def handle_connection(self) -> None:
|
async def handle_connection(self) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -99,7 +101,7 @@ class WebSocketHandler:
|
||||||
)
|
)
|
||||||
|
|
||||||
await self._send_message(state_report)
|
await self._send_message(state_report)
|
||||||
logger.info(f"[TX → Backend] stateReport: CPU {cpu_usage:.1f}%, Memory {memory_usage:.1f}%, "
|
logger.info(f"[TX → Backend] Initial stateReport: CPU {cpu_usage:.1f}%, Memory {memory_usage:.1f}%, "
|
||||||
f"GPU {gpu_usage or 'N/A'}, {len(camera_connections)} cameras")
|
f"GPU {gpu_usage or 'N/A'}, {len(camera_connections)} cameras")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -126,8 +128,14 @@ class WebSocketHandler:
|
||||||
)
|
)
|
||||||
|
|
||||||
await self._send_message(state_report)
|
await self._send_message(state_report)
|
||||||
logger.info(f"[TX → Backend] Heartbeat: CPU {cpu_usage:.1f}%, Memory {memory_usage:.1f}%, "
|
|
||||||
f"GPU {gpu_usage or 'N/A'}, {len(camera_connections)} cameras")
|
# Only log full details every 10th heartbeat, otherwise just show a dot
|
||||||
|
self._heartbeat_count += 1
|
||||||
|
if self._heartbeat_count % 10 == 0:
|
||||||
|
logger.info(f"[TX → Backend] Heartbeat #{self._heartbeat_count}: CPU {cpu_usage:.1f}%, Memory {memory_usage:.1f}%, "
|
||||||
|
f"GPU {gpu_usage or 'N/A'}, {len(camera_connections)} cameras")
|
||||||
|
else:
|
||||||
|
print(".", end="", flush=True) # Just show a dot to indicate heartbeat activity
|
||||||
|
|
||||||
await asyncio.sleep(HEARTBEAT_INTERVAL)
|
await asyncio.sleep(HEARTBEAT_INTERVAL)
|
||||||
|
|
||||||
|
@ -217,7 +225,14 @@ class WebSocketHandler:
|
||||||
'model_name': subscription.modelName
|
'model_name': subscription.modelName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Check if model set has changed to avoid redundant processing
|
||||||
|
current_model_ids = set(unique_models.keys())
|
||||||
|
if current_model_ids == self._last_processed_models:
|
||||||
|
logger.debug(f"[Model Management] Model set unchanged {list(current_model_ids)}, skipping checks")
|
||||||
|
return
|
||||||
|
|
||||||
logger.info(f"[Model Management] Processing {len(unique_models)} unique models: {list(unique_models.keys())}")
|
logger.info(f"[Model Management] Processing {len(unique_models)} unique models: {list(unique_models.keys())}")
|
||||||
|
self._last_processed_models = current_model_ids
|
||||||
|
|
||||||
# Check and download models concurrently
|
# Check and download models concurrently
|
||||||
download_tasks = []
|
download_tasks = []
|
||||||
|
@ -337,10 +352,8 @@ class WebSocketHandler:
|
||||||
try:
|
try:
|
||||||
json_message = serialize_outgoing_message(message)
|
json_message = serialize_outgoing_message(message)
|
||||||
await self.websocket.send_text(json_message)
|
await self.websocket.send_text(json_message)
|
||||||
# Log heartbeats at INFO level with simplified format
|
# Log non-heartbeat messages only (heartbeats are logged in their respective functions)
|
||||||
if hasattr(message, 'type') and message.type == 'stateReport':
|
if not (hasattr(message, 'type') and message.type == 'stateReport'):
|
||||||
logger.info(f"[TX → Backend] {message.type}")
|
|
||||||
else:
|
|
||||||
logger.info(f"[TX → Backend] {json_message}")
|
logger.info(f"[TX → Backend] {json_message}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to send WebSocket message: {e}")
|
logger.error(f"Failed to send WebSocket message: {e}")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue