From 5a91b54fdd0dd2570a6c8060940556e022d185a8 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Thu, 25 Jan 2024 22:16:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E4=B8=80=E4=B8=8B=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=B1=95=E7=A4=BA=E7=9A=84=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index bedaf39..841d37a 100644 --- a/main.py +++ b/main.py @@ -230,12 +230,19 @@ async def add_message(data: Dict[str, Any]): load_str: float = data["load"] * 100 online_node: int = data["currentNodes"] online_bandwidth: int = data["bandwidth"] + data_lens = ["B", "KB", "MB", "GB", "TB"] + for i in range(5): + if data_bandwidth < 1024: + data_bandwidth = round(data_bandwidth, 5) + data_bandwidth = f"{data_bandwidth}{data_lens[i]}" + break + data_bandwidth /= 1024 report_msg = ( "OpenBMCLAPI 状态:\n" f"在线节点: {online_node} 带宽: {online_bandwidth}Mbps\n" f"实时负载带宽: {data_bandwidth:.5f}Mbps 负载: {load_str:.3f}%\n" - f"当日 总请求: {data_hits} 总数据量: {data_bytes / 1024 / 1024:.3f}MB" + f"当日 总请求: {data_hits} 总数据量: {data_bytes}" ) await sio.emit( "sendMessage",