diff --git a/api/sys_monitor_api.py b/api/sys_monitor_api.py index 1d0219d..d5c107a 100644 --- a/api/sys_monitor_api.py +++ b/api/sys_monitor_api.py @@ -22,16 +22,16 @@ async def websocket_endpoint( await manager.connect(websocket) logger.info("ws开始连接....") logger.info("websocket client ip==>{} port===>{}".format(websocket.client.host, websocket.client.port)) - message = {"disk_info": await get_disk_info(), "sys_info": await get_sys_info(), - "cpu_info": await get_cpu_info(), "memory_info": await ge_mem_info()} try: while True: + message = {"disk_info": await get_disk_info(), "sys_info": await get_sys_info(), + "cpu_info": await get_cpu_info(), "memory_info": await ge_mem_info()} try: - data = await asyncio.wait_for(websocket.receive_text(), 3) + await asyncio.wait_for(websocket.receive_text(), 3) await manager.send_json(message, websocket) except asyncio.TimeoutError: - logger.info("开始推送数据.......") + print("推送数据......", message) await manager.send_json(message, websocket) - except (WebSocketDisconnect, RuntimeError,): + except (WebSocketDisconnect, RuntimeError): logger.info("ws开始关闭连接.....") manager.disconnect(websocket)