From 51f7ee9ad0ac7405e2ee580fef9d255896bcbf89 Mon Sep 17 00:00:00 2001 From: hz4th_coder Date: Mon, 1 Jun 2026 16:17:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E7=9B=91=E6=8E=A7API=E8=BF=94=E5=9B=9E=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 匹配JavaScript期待的数据结构: - system.uptime(系统运行时间) - system.boot_time(启动时间) - system.process_count(进程数) - cpu.count/cpu.logical(CPU核心数) - disk.free_gb(磁盘剩余空间) - network.sent_mb/recv_mb(累计流量) - network.sent_speed/recv_speed(实时网速) 确保前端能正确显示所有系统资源信息 --- routes_system.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/routes_system.py b/routes_system.py index 5d67b97..1738a2b 100644 --- a/routes_system.py +++ b/routes_system.py @@ -6,7 +6,7 @@ import os import subprocess import time -from flask import jsonify +from datetime import datetime from utils import log_message, get_cpu_temperatures, load_alert_config try: @@ -82,10 +82,15 @@ def register_system_routes(app): return jsonify({ 'available': True, + 'system': { + 'uptime': uptime_str, + 'boot_time': datetime.fromtimestamp(boot_time).strftime('%Y-%m-%d %H:%M:%S'), + 'process_count': process_count + }, 'cpu': { 'percent': cpu_percent, - 'count_physical': cpu_count, - 'count_logical': cpu_count_logical, + 'count': cpu_count, + 'logical': cpu_count_logical, 'temp_package_0': cpu_temps.get('package_0'), 'temp_package_1': cpu_temps.get('package_1') }, @@ -98,14 +103,15 @@ def register_system_routes(app): 'disk': { 'total_gb': disk_total_gb, 'used_gb': disk_used_gb, + 'free_gb': round(disk.free / (1024**3), 2), 'percent': disk_percent }, 'network': { - 'upload_speed_kb': round(upload_speed, 2), - 'download_speed_kb': round(download_speed, 2) - }, - 'process_count': process_count, - 'uptime': uptime_str + 'sent_mb': round(net.bytes_sent / (1024**2), 2), + 'recv_mb': round(net.bytes_recv / (1024**2), 2), + 'sent_speed': round(upload_speed, 2), + 'recv_speed': round(download_speed, 2) + } }) except Exception as e: return jsonify({'error': str(e)}), 500