feat: 实现 OpenClaw Mission Control 仪表盘框架

- 创建 API Blueprint 模块结构
- 实现系统状态 API (CPU/内存/磁盘/进程)
- 实现服务状态 API
- 创建仪表盘页面模板
- 添加仪表盘 CSS 样式
- 添加仪表盘 JavaScript 交互
- 登录后自动跳转到仪表盘
This commit is contained in:
小白
2026-03-12 20:42:12 +08:00
parent ed6d0133ae
commit f1e4185c8f
10 changed files with 935 additions and 3 deletions

12
api/__init__.py Normal file
View File

@@ -0,0 +1,12 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
OpenClaw Mission Control - API Blueprint
作者:小白 🐶
"""
from flask import Blueprint
api = Blueprint('api', __name__, url_prefix='/api')
from . import status, sessions, nodes, skills, memory

22
api/memory.py Normal file
View File

@@ -0,0 +1,22 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
记忆管理 API
作者:小白 🐶
"""
from flask import jsonify
from . import api
@api.route('/memory')
def get_memory():
"""获取记忆统计"""
# TODO: 实现 OpenClaw 记忆查询
return jsonify({
'success': True,
'data': {
'total': 0,
'today': 0
},
'message': '记忆管理功能开发中'
})

19
api/nodes.py Normal file
View File

@@ -0,0 +1,19 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
节点管理 API
作者:小白 🐶
"""
from flask import jsonify
from . import api
@api.route('/nodes')
def get_nodes():
"""获取节点列表"""
# TODO: 实现 OpenClaw 节点查询
return jsonify({
'success': True,
'data': [],
'message': '节点管理功能开发中'
})

19
api/sessions.py Normal file
View File

@@ -0,0 +1,19 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
会话管理 API
作者:小白 🐶
"""
from flask import jsonify
from . import api
@api.route('/sessions')
def get_sessions():
"""获取会话列表"""
# TODO: 实现 OpenClaw 会话查询
return jsonify({
'success': True,
'data': [],
'message': '会话管理功能开发中'
})

19
api/skills.py Normal file
View File

@@ -0,0 +1,19 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
技能管理 API
作者:小白 🐶
"""
from flask import jsonify
from . import api
@api.route('/skills')
def get_skills():
"""获取技能列表"""
# TODO: 实现 OpenClaw 技能查询
return jsonify({
'success': True,
'data': [],
'message': '技能管理功能开发中'
})

104
api/status.py Normal file
View File

@@ -0,0 +1,104 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
系统状态 API
作者:小白 🐶
"""
import subprocess
import psutil
from flask import jsonify
from . import api
@api.route('/status')
def get_status():
"""获取系统状态"""
try:
# CPU 使用率
cpu_percent = psutil.cpu_percent(interval=1)
# 内存使用
memory = psutil.virtual_memory()
memory_percent = memory.percent
memory_used = round(memory.used / (1024**3), 2)
memory_total = round(memory.total / (1024**3), 2)
# 磁盘使用
disk = psutil.disk_usage('/')
disk_percent = disk.percent
disk_used = round(disk.used / (1024**3), 2)
disk_total = round(disk.total / (1024**3), 2)
# 系统运行时间
uptime_seconds = psutil.boot_time()
# 进程数
process_count = len(psutil.pids())
return jsonify({
'success': True,
'data': {
'cpu': {
'percent': cpu_percent
},
'memory': {
'percent': memory_percent,
'used': memory_used,
'total': memory_total,
'unit': 'GB'
},
'disk': {
'percent': disk_percent,
'used': disk_used,
'total': disk_total,
'unit': 'GB'
},
'process_count': process_count,
'uptime': uptime_seconds
}
})
except Exception as e:
return jsonify({
'success': False,
'error': str(e)
})
@api.route('/status/services')
def get_services():
"""获取服务状态"""
services = []
# 检查各服务状态
service_list = [
('Flask', 5000),
('思源笔记', 6806),
('Gitea', 3000),
('NocoDB', 8080),
('Memory Viewer', 18798)
]
for name, port in service_list:
try:
result = subprocess.run(
['ss', '-tln'],
capture_output=True,
text=True,
timeout=5
)
is_running = f':{port}' in result.stdout
services.append({
'name': name,
'port': port,
'status': 'running' if is_running else 'stopped'
})
except:
services.append({
'name': name,
'port': port,
'status': 'unknown'
})
return jsonify({
'success': True,
'data': services
})