改进一下数据展示的方式

This commit is contained in:
shenjack 2024-01-25 22:16:26 +08:00
parent b086eeb08c
commit 5a91b54fdd
Signed by: shenjack
GPG Key ID: 7B1134A979775551

View File

@ -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",