MCPcopy
hub / github.com/kevwan/tproxy

github.com/kevwan/tproxy @v0.9.2 sqlite

repository ↗ · DeepWiki ↗ · release v0.9.2 ↗
106 symbols 240 edges 18 files 2 documented · 2%
README

tproxy

English | 简体中文 | 日本語

Go Go Report Card Release License: MIT

Buy Me A Coffee

为啥写这个工具

当我在做后端开发或者写 go-zero 的时候,经常会需要监控网络连接,分析请求内容。比如: 1. 分析 gRPC 连接何时连接、何时重连 2. 分析 MySQL 连接池,当前多少连接,连接的生命周期是什么策略 3. 也可以用来观察和分析任何 TCP 连接

安装

$ GOPROXY=https://goproxy.cn/,direct go install github.com/kevwan/tproxy@latest

或者使用 docker 镜像:

$ docker run --rm -it -p <listen-port>:<listen-port> -p <remote-port>:<remote-port> kevinwan/tproxy:v1 tproxy -l 0.0.0.0 -p <listen-port> -r host.docker.internal:<remote-port>

arm64 系统:

$ docker run --rm -it -p <listen-port>:<listen-port> -p <remote-port>:<remote-port> kevinwan/tproxy:v1-arm64 tproxy -l 0.0.0.0 -p <listen-port> -r host.docker.internal:<remote-port>

Windows:

$ scoop install tproxy

用法

$ tproxy --help
Usage of tproxy:
  -d duration
        the delay to relay packets
  -down int
        Downward speed limit(bytes/second)
  -l string
        Local address to listen on (default "localhost")
  -p int
        Local port to listen on, default to pick a random port
  -q    Quiet mode, only prints connection open/close and stats, default false
  -r string
        Remote address (host:port) to connect
  -s    Enable statistics
  -t string
        The type of protocol, currently support http2, grpc, redis and mongodb
  -up int
        Upward speed limit(bytes/second)

示例

分析 gRPC 连接

$ tproxy -p 8088 -r localhost:8081 -t grpc -d 100ms
  • 侦听在 localhost 和 8088 端口
  • 重定向请求到 localhost:8081
  • 识别数据包格式为 gRPC
  • 数据包延迟100毫秒

image

分析 MySQL 连接

$ tproxy -p 3307 -r localhost:3306

image

查看网络状况(重传率和RTT)

$ tproxy -p 3307 -r remotehost:3306 -s -q

image

查看连接池(总连接数、最大并发连接数、最长生命周期等)

$ tproxy -p 3307 -r :3306 -s -q

image

欢迎 star!⭐

如果你正在使用或者觉得这个项目对你有帮助,请 star 支持,感谢!

Extension points exported contracts — how you extend this code

Interop (Interface)
(no doc) [7 implementers]
protocol/interop.go
Stater (Interface)
(no doc) [4 implementers]
stat.go

Core symbols most depended-on inside this repo

PrintlnWithTime
called by 21
display/print.go
readInt32
called by 11
protocol/mongo.go
PrintfWithTime
called by 10
display/print.go
readBson2Json
called by 9
protocol/mongo.go
readString
called by 7
protocol/mongo.go
write
called by 5
protocol/grpc.go
Dump
called by 5
protocol/interop.go
stop
called by 3
conn.go

Shape

Method 51
Function 32
Struct 19
Interface 3
TypeAlias 1

Languages

Go100%

Modules by API surface

stat.go16 symbols
protocol/mysql.go15 symbols
protocol/mongo.go11 symbols
conn.go9 symbols
stat_linux.go8 symbols
protocol/http2.go8 symbols
stat+polyfill.go6 symbols
counter.go6 symbols
protocol/interop.go5 symbols
tcpstat_linux.go4 symbols
protocol/grpc.go4 symbols
delayedwriter.go3 symbols

Dependencies from manifests, versioned

github.com/clipperhouse/displaywidthv0.6.0 · 1×
github.com/clipperhouse/stringishv0.1.1 · 1×
github.com/clipperhouse/uax29/v2v2.3.0 · 1×
github.com/eclipse/paho.mqtt.golangv1.5.1 · 1×
github.com/mattn/go-colorablev0.1.14 · 1×
github.com/mattn/go-isattyv0.0.20 · 1×
github.com/mattn/go-runewidthv0.0.19 · 1×
github.com/olekukonko/catv0.0.0-2025091110415 · 1×
github.com/olekukonko/errorsv1.1.0 · 1×
github.com/olekukonko/llv0.1.3 · 1×

For agents

$ claude mcp add tproxy \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact