witr
witr 旨在解答一个核心问题:“为什么这个在运行?” 它追溯进程的因果链,说明一个运行中事物的来源、启动方式及其责任链,并以单个人性化输出或交互式 TUI(终端用户界面)仪表板呈现。
💡 核心概念
witr 将所有查询(端口、服务、容器等)都视为一个“进程问题”,最终都会映射到 PID(进程标识符)。
一旦识别 PID,witr 就会构建因果链解释该 PID 存在的原因。
⚡️ 一键安装
# Linux, macOS & FreeBSD
curl -fsSL https://raw.githubusercontent.com/pranshuparmar/witr/main/install.sh | bash
# Windows (PowerShell)
irm https://raw.githubusercontent.com/pranshuparmar/witr/main/install.ps1 | iex
📦 包管理器
| 系统 | 命令 |
|---|---|
| macOS & Linux | brew install witr |
| Conda | conda install -c conda-forge witr |
| Nix | nix run github:pranshuparmar/witr |
| Go | go install github.com/pranshuparmar/witr/cmd/witr@latest |
📦 社区维护状态:查看 Repology 获取各发行版的打包状态。
🚀 快速上手
TUI 交互模式
直接运行 witr 或 witr -i,开启实时仪表板,探索进程和端口,支持鼠标点击与排序。
命令行示例
# 按名称查询进程
witr node
# 按端口查询
witr --port 5000
# 查询持有文件的进程
witr --file /var/lib/dpkg/lock
# 显示详细环境变量
witr --env --pid 1234
# 多条件混合查询
witr nginx --port 5432 --pid 1234
⚙️ 主要参数
| 参数 | 说明 |
|---|---|
-i, --interactive |
进入交互式 TUI 模式 |
-x, --exact |
精确匹配进程名(默认支持子串匹配) |
-f, --file |
查找打开指定文件的进程(可重复) |
--port |
查找占用指定端口的进程 |
--pid |
指定 PID 查询 |
--env |
显示进程环境变量 |
--tree |
以树状结构展示进程层级 |
--short |
简洁输出模式(仅因果链) |
📺 输出示例
基于进程名的查询
Target : node
Process : node (pid 14233)
User : pm2
Command : node index.js
Started : 2 days ago (Mon 2025-02-02 11:42:10 +05:30)
Restarts : 1
Why It Exists : systemd (pid 1) → pm2 (pid 5034) → node (pid 14233)
Listening : 127.0.0.1:5001
清晰解释了进程是由 systemd 启动 pm2,再由 pm2 启动 node 的完整因果链。
多匹配时的提示
如果找到多个匹配进程,witr 会列出所有候选项,并提示你使用 --pid 参数精确查询。
🖥️ 平台支持与权限
| 平台 | 支持情况 | 实现方式 |
|---|---|---|
| Linux (x86_64, arm64) | ✅ 全功能 | 读取 /proc 文件系统 |
| macOS (x86_64, arm64) | ✅ 全功能 | ps, lsof, sysctl, pgrep |
| Windows (x86_64, arm64) | ✅ 全功能 | Get-CimInstance, tasklist, netstat |
| FreeBSD (x86_64, arm64) | ✅ 全功能 | procstat, ps, lsof |
🔑 权限提示:当进程信息不全时(尤其在 Linux/FreeBSD),请使用
sudo运行witr以获取完整信息。在 macOS 上,witr 使用常规系统命令,通常无需提权。
🎯 设计目标
- 解释“为什么存在”:不只告诉你在运行什么,更重要的是说明它为何运行。
- 极简配置:零配置,开箱即用。
- 安全只读:所有操作均为只读,不会修改系统状态。
- 信息清晰:默认单屏展示,优先保证可读性,而非信息的绝对完整性。
wirt 并非监控工具、编排工具或自动修复工具。它专注于快速定位“因果”。
