Metadata-Version: 2.4
Name: remo-gpu
Version: 0.1.2
Summary: Monitor GPUs on every SSH host defined in ~/.ssh/config.
Author: Leon
License: MIT License
        
        Copyright (c) 2025 Bobby
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
        
Project-URL: Homepage, https://github.com/boyuaner/remo-gpu
Project-URL: Repository, https://github.com/boyuaner/remo-gpu
Keywords: gpu,ssh,monitoring,nvidia-smi
Classifier: Development Status :: 4 - Beta
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Environment :: Console
Classifier: Topic :: System :: Monitoring
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: rich<14,>=13
Requires-Dist: textual<0.70,>=0.60
Dynamic: license-file

# Remo-GPU

一个基于 Python 的命令行工具，用于批量监控 `~/.ssh/config` 中所有主机的 GPU 使用情况。脚本会对每台主机执行一次 `nvidia-smi`（或自定义命令），并以表格形式实时刷新结果。发布到 PyPI 后即可：

```bash
pip install remo-gpu
remo-gpu --interval 3
```

## 特性

- 自动解析 `~/.ssh/config` 及其 `Include` 指令，获取可用主机别名
- 并发执行 SSH 命令，默认最多 8 台同时查询
- Textual 卡片式 UI 默认启用，可滚动查看所有主机
- Rich 彩色表格、纯文本模式按需切换
- 启动时自动探测不可连接主机，单独列出并跳过后续刷新

## 快速开始

1. 确保本地 Python ≥ 3.9 且可运行 `ssh`
2. 主机上必须安装 `nvidia-smi`（NVIDIA 驱动自带），并已配置免密登录
3. 在源码目录或安装后运行：

```bash
python3 -m remo_gpu --interval 3
# 或使用安装后的 CLI
remo-gpu --interval 3
```

默认每 5 秒刷新一次，可按 `Ctrl + C` 退出。

## 常用参数

```bash
python3 -m remo_gpu \
  --interval 3 \
  --timeout 8 \
  --hosts gpu-a gpu-b \
  --identity-file ~/.ssh/id_rsa \
  --ssh-option "-o StrictHostKeyChecking=no" \
  --ssh-option "-o UserKnownHostsFile=/dev/null"
```

- `--hosts`: 仅监控指定 Host 别名
- `--interval`: 刷新间隔（秒），默认 5
- `--timeout`: 单次 SSH 命令超时（秒），默认 10
- `--identity-file`: 指定私钥文件，等价于 `ssh -i`
- `--ssh-option`: 其他 SSH 原始参数，可多次传入
- `--remote-command`: 自定义远程查询命令，默认执行 `nvidia-smi`
- `--interval-once`: 只运行一次后退出
- `--no-clear`: 禁用清屏，便于查看更长的输出历史

### Rich / Textual UI（可选）

如需更接近 nvitop 的可视化体验，可根据需要安装 `rich` 或 `textual`：

```bash
# Textual 模式（默认，建议同时安装 rich + textual）
pip install rich textual
remo-gpu --interval 2

# Rich 彩色表格
pip install rich
remo-gpu --ui rich --interval 2
```

- 默认 `textual`：可滚动卡片（依赖 rich+textual），支持 ↑/↓、`r`、`q`；
- `rich`：彩色表格＋进度条；
- `plain`：纯文本输出，便于记录日志。

## 使用 uvx 运行

借助 [uv](https://github.com/astral-sh/uv) 的 `uvx` 子命令，可以在隔离环境中运行脚本而不手动创建虚拟环境：

```bash
# 在项目根目录
uvx --from . remo-gpu --interval 3 --ui plain

# 若需 Rich UI，可顺便拉取依赖
uvx --from . --with rich remo-gpu --ui rich --interval 2

# Textual UI（需 rich + textual）
uvx --from . --with rich --with textual remo-gpu --ui textual
```

`uvx --from .` 会使用当前目录作为包来源；通过 `--with rich/textual` 可以在隔离环境中临时安装对应可选依赖。其余 CLI 参数与直接调用 `python3 -m remo_gpu` 完全一致。

## Bash 版本

如果希望以纯 bash 方式运行，可直接执行 `remo_gpu.sh`：

```bash
bash remo_gpu.sh \
  --interval 3 \
  --hosts gpu-a,gpu-b \
  --ssh-option StrictHostKeyChecking=no \
  --ssh-option UserKnownHostsFile=/dev/null
```

- `--ssh-option` 会被转换为 `ssh -o key=value`
- `--once` 仅输出一次结果
- 兼容 macOS 自带 bash 3.2；若已安装 bash 4+，同样可直接运行

## 提示

- 如 `.ssh/config` 使用了通配符（`Host *`），脚本会自动忽略
- 若首次连接提示主机指纹，可通过 `--ssh-option "-o StrictHostKeyChecking=no"` 关闭严格校验（按需使用）
- 对监控频率要求更高时，适当调小 `--interval` 并增大 `--concurrency`

## 贡献

欢迎根据自身环境扩展输出格式、Prometheus 上报、或结合 `watch`/`tmux` 等工具打造个性化监控面板。*** End Patch

