Hermes 5e69b1c3e2 feat: overhaul process monitoring UI - more info, tree view, details, batch ops
User feedback: '进程比较关键,以下显示太少了,需要继续优化下监控UI'

Process monitor panel was rebuilt:

1. core/monitor.py: 200 -> 500 processes, added PPID / PRI / NICE
   New ps fields: pid ppid user pcpu pmem vsz rss stat pri nice etimes times args
   Python parser: new fields ppid, pri, nice

2. ui/widgets.py MonitorPanel:
   a) Toolbar: search box + sort dropdown (CPU/MEM/PID/start/user/comm)
      + view toggle (Flat / Tree) + CPU% min filter (SpinBox 0-100%)
      + batch kill button
   b) Table: 12 columns (Flat) / 13 cols (Tree + indent col)
      PID PPID USER CPU% MEM% RSS STAT PRI NI '启动' 'CPU时间' 命令
      - Compact row height 20px (was default 30)
      - Extended selection (Ctrl/Shift multi)
      - Color highlights:
          CPU% >=80 red bg+fg bold, >=50 red fg bold, >=20 orange
          MEM% >=15 orange bg+fg bold, >=5 orange
          STAT: Z orange bg + orange-red fg bold, R green, D purple
          NI: negative green, positive orange
      - Red bg on EXTREME rows for instant visibility
   c) Tree view: builds PPID tree with ├─/└─/│ connectors;
      root processes (PID 1) at depth 0, sorted by CPU within siblings.
      Useful for 'which process is spawning these things?'
   d) Right side panel:
      - 进程详情 (QTextEdit dark theme): full PID/PPID/USER/STAT/PRI/NI/
        CPU/MEM/RSS/VSZ/etime/cputime, command, parent process name,
        child processes list (top 10)
      - 🔥 CPU TOP 5 (QListWidget dark): click to jump+select in main table
      - 💾 内存 TOP 5 (QListWidget dark): same
   e) Right-click menu enhanced:
      kill (SIGTERM) | kill -9 (SIGKILL) | batch kill (if multi-select)
      | copy PID | copy command | filter by command | view details
   f) Batch kill: collects all selected PIDs, runs 'kill p1 p2 p3 ...'
      in a single SSH call, then loops 'kill -0' to report survivors.
      One confirmation dialog lists top 10 + '还有 N 个'.
   g) Status row at bottom: 'Ctrl+A 全选, Shift+点击多选, 右键批量操作'

3. test_process_monitor.py: 5/5 tests pass with 500 rows, tree view,
   TOP 5, CPU min filter, etc.

All tests pass: core 6/6 + UI 3/3 + E2E 6/6 + terminal 5/5 + proc 5/5
Build: 57 MB single-file exe.
2026-07-28 22:39:26 +08:00

SSHClient

基于 PyQt5 + paramiko 的 Windows SSH 客户端,支持远程终端、SFTP 文件浏览、CPU/内存/磁盘/网络实时监控,以及 OpenAI 兼容的 AI Agent(可调用工具操作远程主机)。

main

功能特性

模块 说明
多主机管理 增删改查、密码/私钥双认证、配置导入导出、配置持久化到 ~/.sshclient/
远程终端 命令执行 + 输出捕获 + 退出码 + 超时控制 + 常用命令快捷栏
SFTP 文件浏览 目录树浏览、上传/下载(带进度条)、新建目录、删除、重命名、双击进入
实时监控 CPU/内存/负载/启动时间/磁盘/网络速率,1-10 秒可调刷新间隔
AI Agent OpenAI 兼容 APIOpenAI / DeepSeek / Moonshot / 通义千问 / Ollama 等),5 个工具自动调用:执行命令、查指标、列文件、读文件、上传
跨平台 代码兼容 Windows / macOS / LinuxPyQt5 + paramiko

📦 在 Windows 上构建 exe

最简单的方式:双击 build_windows.bat

  1. 安装 Python 3.10+(勾选 Add to PATH
  2. 把整个项目目录拷到 Windows 电脑
  3. 双击 build_windows.bat,等 2-3 分钟
  4. 产物:dist\SSHClient.exe(单文件,约 50-60 MB,可拷给任何人直接双击运行)

手动方式:

python -m venv venv
venv\Scripts\activate
pip install -r requirements.txt
pyinstaller build.spec --clean --noconfirm

🚀 在 Linux/macOS 上开发

./build.sh        # 一键打包当前平台二进制
python main.py    # 直接开发运行

🧪 测试

source venv/bin/activate
python test_core.py   # 核心模块 smoke test(无网络依赖)
python test_ui.py     # UI 组件加载测试(offscreen 渲染)
python test_e2e.py    # 端到端测试(需本机或可访问的 sshd)

🎮 使用说明

1. 添加主机

左侧 新增主机,填主机名/IP、端口、用户名、密码(可选私钥文件)。

2. 连接

选中主机 → 🔌 连接。状态指示器变绿后即可使用。

3. 终端

⌨ 终端 Tab 直接输入命令回车执行。常用命令(pwd / df / free / top / netstat)有快捷按钮。

4. 文件浏览

📁 文件 Tab 双击目录进入,双击文件直接下载。可拖入 / 上传任意文件。

5. 监控

📊 监控 Tab 点击 开始监控,指标会按设定间隔刷新。CPU/内存用大字突出,磁盘用进度条,网络显示当前速率。

6. AI Agent

  1. 先点 ⚙ AI 设置,选择预设(OpenAI/DeepSeek/Kimi/通义千问/Ollama)或自定义填 API Key
  2. 回到 🤖 AI Agent Tab,用自然语言提问:
    • "帮我看 CPU 为什么这么高"
    • "找出 /var/log 下最大的 10 个文件"
    • "重启 nginx 服务"
  3. AI 会自动调用工具(执行命令、查指标等)并给出结论

安全提示:AI Agent 可以执行任意命令,请使用只读权限的 API Key,或在 prompt 中限定危险操作前需确认。

🔌 支持的 AI 提供商

预设 Base URL 模型
OpenAI https://api.openai.com/v1 gpt-4o-mini
DeepSeek https://api.deepseek.com/v1 deepseek-chat
Moonshot Kimi https://api.moonshot.cn/v1 moonshot-v1-8k
通义千问 https://dashscope.aliyuncs.com/compatible-mode/v1 qwen-turbo
智谱 GLM https://open.bigmodel.cn/api/paas/v4 glm-4-flash
Ollama (本地) http://127.0.0.1:11434/v1 qwen2.5:7b
自定义 - 任意 OpenAI 兼容端点

📂 项目结构

sshclient/
├── main.py                # 入口
├── requirements.txt       # 依赖
├── build.spec             # PyInstaller 打包配置
├── build_windows.bat      # Windows 一键打包
├── build.sh               # Linux/macOS 打包
├── core/                  # 业务逻辑
│   ├── ssh_client.py      # SSH 连接 + SFTP
│   ├── monitor.py         # 远程系统监控
│   ├── ai_agent.py        # AI Agent (OpenAI 兼容)
│   └── manager.py         # 多主机管理 + 配置持久化
├── ui/                    # PyQt5 界面
│   ├── main_window.py     # 主窗口
│   ├── widgets.py         # FileBrowser / MonitorPanel / AIChatPanel
│   ├── host_dialog.py     # 主机编辑对话框
│   ├── config_dialog.py   # AI 设置对话框
│   └── workers.py         # 后台线程
└── test_*.py              # 测试脚本

🔧 故障排查

问题 解决
python 不识别 安装 Python 时勾选 "Add Python to PATH"
打包失败 ModuleNotFoundError pip install <module> 后重新打包
exe 启动黑窗闪过 已用 console=False,如还出现请检查杀毒软件
SSH 连接超时 检查防火墙、22 端口、目标主机 sshd 是否运行
AI 设置测试连接失败 检查 API Key 是否正确、Base URL 是否可访问、代理设置

📄 License

MIT

S
Description
No description provided
Readme 361 KiB
2026-07-28 22:01:14 +08:00
Languages
Python 98.5%
Batchfile 0.9%
Shell 0.6%