fix: use process uptime and host-service stats fallback
This commit is contained in:
@@ -211,11 +211,24 @@ def get_server_info_api():
|
||||
disk_used = f"{disk.used / (1024**3):.1f}GB"
|
||||
disk_percent = disk.percent
|
||||
|
||||
boot_time = datetime.fromtimestamp(psutil.boot_time(), tz=BEIJING_TZ)
|
||||
uptime_delta = get_beijing_now() - boot_time
|
||||
days = uptime_delta.days
|
||||
hours = uptime_delta.seconds // 3600
|
||||
uptime = f"{days}天{hours}小时"
|
||||
try:
|
||||
process = psutil.Process()
|
||||
process_start_at = datetime.fromtimestamp(process.create_time(), tz=BEIJING_TZ)
|
||||
uptime_delta = get_beijing_now() - process_start_at
|
||||
except Exception:
|
||||
boot_time = datetime.fromtimestamp(psutil.boot_time(), tz=BEIJING_TZ)
|
||||
uptime_delta = get_beijing_now() - boot_time
|
||||
|
||||
uptime_seconds = max(0, int(uptime_delta.total_seconds()))
|
||||
days = uptime_seconds // 86400
|
||||
hours = (uptime_seconds % 86400) // 3600
|
||||
minutes = (uptime_seconds % 3600) // 60
|
||||
if days > 0:
|
||||
uptime = f"{days}天{hours}小时"
|
||||
elif hours > 0:
|
||||
uptime = f"{hours}小时{minutes}分钟"
|
||||
else:
|
||||
uptime = f"{minutes}分钟"
|
||||
|
||||
return jsonify(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user