fix: 修正系统监控API返回数据结构

匹配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(实时网速)

确保前端能正确显示所有系统资源信息
This commit is contained in:
2026-06-01 16:17:47 +08:00
parent ea904fb2b2
commit 51f7ee9ad0

View File

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