Go进程检查工具

一个用于检查和分析运行中的Go进程的工具,包括goroutine状态、内存统计和二进制信息。

  • by monsterxx03
  • Go
  • 混合部署
  • 97 星标
  • 更新于
在 GitHub 查看 monsterxx03/gospy

使用说明

Go流程检查员

一种用于检查和分析正在运行的Go进程的工具,包括goroutine状态、内存统计和二进制信息。

特性

  • 查看详细的goroutine信息(状态、日程安排信息)
  • 分析进程内存统计信息
  • 跨平台支持(Linux和macOS)
  • 交互式检查终端UI
  • 用于编程访问的HTTP API
  • mcp服务器

安装

go install github.com/monsterxx03/gospy@latest

用法

CLI接口

# Interactive terminal UI
sudo gospy top --pid <pid>

# HTTP API server
sudo gospy serve --port 8974

# Get process summary
sudo gospy summary --pid <pid>

# Get process summary in JSON format
sudo gospy summary --pid <pid> --json

摘要命令选项

  • --pid/-p -目标进程ID(必需)
  • --bin/-b -二进制文件的路径(可选)
  • --json/-j -以JSON格式输出结果

API终点

  • GET /goroutines?pid=<pid> -列出所有goroutines
  • GET /memstats?pid=<pid> -获取内存统计信息
  • GET /runtime?pid=<pid> -获取运行时版本信息

MCP服务器

MCP服务器提供了一个http(streamableHTTP)端点。要启用:

>>> sudo gospy serve --enable-mcp --port 8974

Starting API server on port 8974
Endpoints:
  GET /runtime?pid=<PID>     - Get runtime info
  GET /goroutines?pid=<PID> - Get goroutines list
  GET /memstats?pid=<PID>   - Get memory stats
  GET /mcp   - MCP http endpoint

可用的MCP工具:

  • goroutines -为go进程转储goroutines
  • gomemstats -转储go进程的内存统计信息
  • goruntime -转储go进程的运行时信息
  • pgrep -从进程名称中查找pid

游标中的配置

终端UI控件

  • q -退出
  • r -刷新数据
  • s -暂停/恢复俯视图
  • / -搜索/过滤goroutines

终端用户界面截图

从源头构建

git clone https://github.com/monsterxx03/gospy.git
cd gospy
make

需求

  • 转到1.20+
  • Linux或macOS(仅限苹果Silicon)
  • 根权限(内存访问所需)

根权限

gospy需要root权限才能:

  • 读取进程内存(/proc//Linux上的mem)
  • 在macOS上访问Mach API

使用sudo运行:

sudo gospy top --pid <pid>

对于开发/调试,您可能需要:

  1. 首先构建二进制文件: make
  2. 使用sudo运行: sudo ./gospy [command]

鸣谢

0.7.0版本完全从头开始重写 帮助,编写了90%以上的代码。其他援助来源:

人工智能计算总成本:约2美元

许可证

麻省理工学院-参见 许可证 文件以获取详细信息。