新增转图运行时健康监控与手动预热
变更项:\n1. 在 markdown_to_image 增加 get_md2img_health_snapshot 健康快照能力,输出 runtime 线程、事件循环、浏览器连接、启动来源与 PID 状态。\n2. 新增系统接口 GET /api/system/md2img_health,支持后台查询转图运行时健康信息。\n3. 新增系统接口 POST /api/system/md2img_warmup,支持后台手动触发转图预热并返回最新状态。\n4. 在资源监控页面接入转图健康状态条,展示运行时在线状态、浏览器连接状态及关键摘要信息。\n5. 在资源监控页面增加转图预热与状态刷新按钮,便于线上快速自愈与排障。\n6. 补充中文注释与错误提示,保持后端与前端可观测性一致。
This commit is contained in:
@@ -11,6 +11,7 @@ from collections import deque
|
||||
import gzip
|
||||
import json
|
||||
import yaml
|
||||
from utils.markdown_to_image import get_md2img_health_snapshot, warmup_md2img_browser_sync
|
||||
|
||||
# 创建系统信息蓝图
|
||||
system_bp = Blueprint('system', __name__)
|
||||
@@ -305,6 +306,47 @@ def update_system_llm_config():
|
||||
return jsonify({"success": False, "message": str(e)}), 500
|
||||
|
||||
|
||||
@system_bp.route('/api/system/md2img_health', methods=['GET'])
|
||||
@login_required
|
||||
def get_md2img_health():
|
||||
"""查询 Markdown 转图运行时健康状态。"""
|
||||
try:
|
||||
# 默认只读取状态,不主动拉起 runtime。
|
||||
# 当后台希望“刷新并顺便拉起”时,可传 ensure_runtime=true。
|
||||
ensure_runtime = str(request.args.get('ensure_runtime', 'false')).strip().lower() in {'1', 'true', 'yes', 'on'}
|
||||
data = get_md2img_health_snapshot(ensure_runtime=ensure_runtime)
|
||||
return jsonify({"success": True, "data": data})
|
||||
except Exception as e:
|
||||
logger.error(f"获取 md2img 健康状态失败: {e}")
|
||||
return jsonify({"success": False, "message": str(e)}), 500
|
||||
|
||||
|
||||
@system_bp.route('/api/system/md2img_warmup', methods=['POST'])
|
||||
@login_required
|
||||
def trigger_md2img_warmup():
|
||||
"""手动触发 Markdown 转图浏览器预热。"""
|
||||
try:
|
||||
payload = request.get_json(silent=True) or {}
|
||||
timeout_seconds = int(payload.get('timeout_seconds', 45) or 45)
|
||||
timeout_seconds = max(10, min(timeout_seconds, 180))
|
||||
ok = warmup_md2img_browser_sync(timeout_seconds=timeout_seconds)
|
||||
data = get_md2img_health_snapshot(ensure_runtime=False)
|
||||
if ok:
|
||||
return jsonify({
|
||||
"success": True,
|
||||
"message": f"预热完成(timeout={timeout_seconds}s)",
|
||||
"data": data,
|
||||
})
|
||||
return jsonify({
|
||||
"success": False,
|
||||
"message": f"预热失败(timeout={timeout_seconds}s),请查看运行日志",
|
||||
"data": data,
|
||||
}), 500
|
||||
except Exception as e:
|
||||
logger.error(f"触发 md2img 预热失败: {e}")
|
||||
return jsonify({"success": False, "message": str(e)}), 500
|
||||
|
||||
|
||||
@system_bp.route('/api/restart_service', methods=['POST'])
|
||||
@login_required
|
||||
def restart_service():
|
||||
|
||||
Reference in New Issue
Block a user