Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 47a38032a6 | |||
| b59931f357 | |||
| 1420b08a43 | |||
| cd5bdb5938 | |||
| 69ade8dcbb | |||
| 7926a5b51f | |||
| 26e0ed26e1 |
170
app.py
170
app.py
@@ -799,6 +799,58 @@ def api_system_stats():
|
||||
return jsonify({'error': str(e), 'available': False})
|
||||
|
||||
|
||||
@app.route('/api/system/processes')
|
||||
def api_system_processes():
|
||||
"""获取CPU占用最高的进程列表"""
|
||||
if not HAS_PSUTIL:
|
||||
return jsonify({'error': 'psutil未安装', 'available': False})
|
||||
|
||||
try:
|
||||
limit = int(request.args.get('limit', 10))
|
||||
limit = max(1, min(50, limit)) # 限制1-50
|
||||
|
||||
processes = []
|
||||
for proc in psutil.process_iter(['pid', 'name', 'memory_percent', 'status', 'create_time', 'exe', 'cmdline']):
|
||||
try:
|
||||
pinfo = proc.info
|
||||
# 获取实时CPU占用(需要单独调用)
|
||||
cpu_percent = proc.cpu_percent(interval=0.1)
|
||||
|
||||
# 格式化命令行
|
||||
cmdline = pinfo.get('cmdline', [])
|
||||
cmdline_str = ' '.join(cmdline) if cmdline else pinfo['name']
|
||||
if len(cmdline_str) > 60:
|
||||
cmdline_str = cmdline_str[:60] + '...'
|
||||
|
||||
# 启动时间
|
||||
create_time = datetime.fromtimestamp(pinfo['create_time']).strftime('%m-%d %H:%M')
|
||||
|
||||
processes.append({
|
||||
'pid': pinfo['pid'],
|
||||
'name': pinfo['name'],
|
||||
'cpu': cpu_percent,
|
||||
'memory': pinfo['memory_percent'] or 0,
|
||||
'status': pinfo['status'],
|
||||
'create_time': create_time,
|
||||
'exe': pinfo.get('exe', '') or '',
|
||||
'cmdline': cmdline_str
|
||||
})
|
||||
except (psutil.NoSuchProcess, psutil.AccessDenied):
|
||||
continue
|
||||
|
||||
# 按CPU占用排序,取前N个
|
||||
processes.sort(key=lambda x: x['cpu'], reverse=True)
|
||||
top_processes = processes[:limit]
|
||||
|
||||
return jsonify({
|
||||
'available': True,
|
||||
'processes': top_processes,
|
||||
'count': len(top_processes)
|
||||
})
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e), 'available': False})
|
||||
|
||||
|
||||
def guess_cron_name(command):
|
||||
"""从命令推断任务名称"""
|
||||
keywords = {
|
||||
@@ -1103,7 +1155,7 @@ HTML_TEMPLATE = '''<!DOCTYPE html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>项目服务管理面板 v3.2</title>
|
||||
<title>项目服务管理面板 v3.3.1</title>
|
||||
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>📊</text></svg>">
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<link href="https://cdn.jsdelivr.net/npm/remixicon@3.5.0/fonts/remixicon.css" rel="stylesheet">
|
||||
@@ -1328,7 +1380,7 @@ HTML_TEMPLATE = '''<!DOCTYPE html>
|
||||
</div>
|
||||
<div class="card rounded-xl p-6">
|
||||
<div class="flex items-center justify-between mb-4">
|
||||
<h3 class="font-bold text-lg flex items-center gap-2"><i class="ri-memory-card-line text-green-400"></i> 内存使用</h3>
|
||||
<h3 class="font-bold text-lg flex items-center gap-2"><i class="ri-database-2-line text-green-400"></i> 内存使用</h3>
|
||||
<span id="memPercent" class="text-2xl font-bold text-green-400">-</span>
|
||||
</div>
|
||||
<div class="w-full bg-gray-700 rounded-full h-4 mb-2">
|
||||
@@ -1394,7 +1446,7 @@ HTML_TEMPLATE = '''<!DOCTYPE html>
|
||||
</div>
|
||||
<div class="threshold-item">
|
||||
<div class="threshold-label">
|
||||
<i class="ri-memory-card-line threshold-icon text-green-400"></i>
|
||||
<i class="ri-database-2-line threshold-icon text-green-400"></i>
|
||||
<span class="text-gray-300 text-sm">内存使用率</span>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
@@ -1464,6 +1516,32 @@ HTML_TEMPLATE = '''<!DOCTYPE html>
|
||||
</select>
|
||||
<span id="realtimeIndicator" class="text-xs text-green-400 ml-1 hidden">●</span>
|
||||
</div>
|
||||
<div class="flex items-center gap-2 ml-4">
|
||||
<input type="checkbox" id="showProcessListCheck" class="w-4 h-4 cursor-pointer" onchange="toggleProcessList()">
|
||||
<label for="showProcessListCheck" class="text-gray-300 text-xs cursor-pointer">显示进程列表</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 进程列表(实时监控时显示) -->
|
||||
<div id="processListSection" class="hidden mt-6">
|
||||
<div class="flex items-center justify-between mb-3">
|
||||
<h3 class="font-bold text-gray-200 flex items-center gap-2">
|
||||
<i class="ri-bar-chart-horizontal text-purple-400"></i> CPU占用最高的进程
|
||||
</h3>
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="text-gray-400 text-xs">显示数量:</span>
|
||||
<select id="processLimitSelect" class="bg-gray-700 text-gray-200 px-2 py-1 rounded text-xs" onchange="loadTopProcesses()">
|
||||
<option value="5">5</option>
|
||||
<option value="10" selected>10</option>
|
||||
<option value="15">15</option>
|
||||
<option value="20">20</option>
|
||||
<option value="30">30</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div id="processList" class="space-y-2">
|
||||
<div class="text-gray-500 text-center py-4"><i class="ri-loader-4-line animate-spin"></i> 加载中...</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1834,8 +1912,10 @@ HTML_TEMPLATE = '''<!DOCTYPE html>
|
||||
clearInterval(realtimeTimer);
|
||||
realtimeTimer = null;
|
||||
document.getElementById('realtimeCheck').checked = false;
|
||||
document.getElementById('showProcessListCheck').checked = false;
|
||||
document.getElementById('realtimeToggle').classList.remove('active');
|
||||
document.getElementById('realtimeIndicator').classList.add('hidden');
|
||||
document.getElementById('processListSection').classList.add('hidden');
|
||||
}
|
||||
|
||||
if (tab === 'cron') {
|
||||
@@ -2059,11 +2139,63 @@ HTML_TEMPLATE = '''<!DOCTYPE html>
|
||||
// 检查阈值
|
||||
checkThresholds(data);
|
||||
|
||||
// 如果实时监控和进程列表都开启,加载进程列表
|
||||
if (document.getElementById('realtimeCheck').checked && document.getElementById('showProcessListCheck').checked) {
|
||||
loadTopProcesses();
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.error('系统资源加载失败:', e);
|
||||
}
|
||||
}
|
||||
|
||||
// 加载CPU占用最高的进程
|
||||
async function loadTopProcesses() {
|
||||
try {
|
||||
const limit = document.getElementById('processLimitSelect').value;
|
||||
const res = await fetch(`/api/system/processes?limit=${limit}`);
|
||||
const data = await res.json();
|
||||
|
||||
if (!data.available) {
|
||||
document.getElementById('processList').innerHTML = '<div class="text-red-400 text-center py-4">无法获取进程信息</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
const list = document.getElementById('processList');
|
||||
if (data.processes.length === 0) {
|
||||
list.innerHTML = '<div class="text-gray-500 text-center py-4">暂无进程数据</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
list.innerHTML = data.processes.map(proc => `
|
||||
<div class="card rounded-lg p-3 hover:border-gray-500 transition-colors">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex items-center gap-3 min-w-0">
|
||||
<span class="text-purple-400 font-mono text-sm">${proc.pid}</span>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="text-gray-200 truncate">${proc.name}</div>
|
||||
<div class="text-gray-500 text-xs truncate">${proc.cmdline || proc.exe}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-4 text-xs shrink-0">
|
||||
<div class="text-right">
|
||||
<span class="text-blue-400 font-bold">${proc.cpu.toFixed(1)}%</span>
|
||||
<span class="text-gray-500 ml-1">CPU</span>
|
||||
</div>
|
||||
<div class="text-right">
|
||||
<span class="text-green-400 font-bold">${proc.memory.toFixed(1)}%</span>
|
||||
<span class="text-gray-500 ml-1">内存</span>
|
||||
</div>
|
||||
<div class="text-gray-400">${proc.create_time}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`).join('');
|
||||
} catch (e) {
|
||||
console.error('进程列表加载失败:', e);
|
||||
}
|
||||
}
|
||||
|
||||
function toggleRealtime() {
|
||||
const checked = document.getElementById('realtimeCheck').checked;
|
||||
const toggle = document.getElementById('realtimeToggle');
|
||||
@@ -2076,9 +2208,15 @@ HTML_TEMPLATE = '''<!DOCTYPE html>
|
||||
loadSystemStats();
|
||||
// 启动定时器
|
||||
realtimeTimer = setInterval(loadSystemStats, realtimeInterval * 1000);
|
||||
// 如果进程列表开关也开启,则显示并加载
|
||||
if (document.getElementById('showProcessListCheck').checked) {
|
||||
document.getElementById('processListSection').classList.remove('hidden');
|
||||
loadTopProcesses();
|
||||
}
|
||||
} else {
|
||||
toggle.classList.remove('active');
|
||||
indicator.classList.add('hidden');
|
||||
document.getElementById('processListSection').classList.add('hidden');
|
||||
// 停止定时器
|
||||
if (realtimeTimer) {
|
||||
clearInterval(realtimeTimer);
|
||||
@@ -2086,6 +2224,19 @@ HTML_TEMPLATE = '''<!DOCTYPE html>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function toggleProcessList() {
|
||||
const checked = document.getElementById('showProcessListCheck').checked;
|
||||
const realtimeChecked = document.getElementById('realtimeCheck').checked;
|
||||
const processSection = document.getElementById('processListSection');
|
||||
|
||||
if (checked && realtimeChecked) {
|
||||
processSection.classList.remove('hidden');
|
||||
loadTopProcesses();
|
||||
} else {
|
||||
processSection.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
// IP 保存
|
||||
function saveExternalIp() {
|
||||
@@ -2426,17 +2577,16 @@ HTML_TEMPLATE = '''<!DOCTYPE html>
|
||||
}
|
||||
|
||||
const resourceNames = { 'cpu': 'CPU', 'memory': '内存', 'disk': '磁盘' };
|
||||
const triggerNames = {
|
||||
'single': '一次性',
|
||||
'continuous': `连续${rule.triggerParam}次`,
|
||||
'duration': `持续${rule.triggerParam}秒`,
|
||||
'average': `平均${rule.triggerParam}次`
|
||||
};
|
||||
|
||||
list.innerHTML = rules.map(rule => {
|
||||
const silentInfo = rule.silentEnabled ? `静默:${rule.silentStart}-${rule.silentEnd}` : '';
|
||||
const triggerType = rule.triggerType || 'single';
|
||||
const triggerDisplay = triggerNames[triggerType] || triggerNames['single'];
|
||||
const triggerParam = rule.triggerParam || 3;
|
||||
let triggerDisplay = '一次性';
|
||||
if (triggerType === 'continuous') triggerDisplay = `连续${triggerParam}次`;
|
||||
else if (triggerType === 'duration') triggerDisplay = `持续${triggerParam}秒`;
|
||||
else if (triggerType === 'average') triggerDisplay = `平均${triggerParam}次`;
|
||||
|
||||
return `
|
||||
<div class="flex items-center justify-between bg-gray-700/50 px-3 py-2 rounded-lg">
|
||||
<div class="flex items-center gap-3 flex-wrap">
|
||||
|
||||
30284
logs/app.log
30284
logs/app.log
File diff suppressed because it is too large
Load Diff
@@ -64,6 +64,19 @@
|
||||
"git_repo": "http://192.168.2.8:12007/coder/ai-chat-system",
|
||||
"version": "v2.5.4"
|
||||
},
|
||||
{
|
||||
"id": "ai-chat-app",
|
||||
"name": "AI Chat App",
|
||||
"type": "web",
|
||||
"ports": [19021],
|
||||
"directory": "works/ai-chat-app-new/backend",
|
||||
"start_cmd": "mkdir -p logs && nohup python3 app.py > logs/app.log 2>&1 & disown",
|
||||
"health_url": "http://localhost:19021/api/config",
|
||||
"description": "AI对话助手移动端应用,智能体对话、TTS语音、思考模式",
|
||||
"admin_url": "http://localhost:19021/admin",
|
||||
"git_repo": "http://192.168.2.8:12007/coder/ai-chat-app-v4",
|
||||
"version": "v3.15.1"
|
||||
},
|
||||
{
|
||||
"id": "product-crawler",
|
||||
"name": "产品参数爬取系统",
|
||||
|
||||
Reference in New Issue
Block a user