Skip to content

bingoohuang/tproxy

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tproxy

English | 简体中文

img.png

Buy Me A Coffee

Why I wrote this tool

When I develop backend services and write go-zero, I often need to monitor the network traffic. For example:

  1. monitoring gRPC connections, when to connect and when to reconnect
  2. monitoring MySQL connection pools, how many connections and figure out the lifetime policy
  3. monitoring any TCP connections on the fly

Installation

$ go install github.com/bingoohuang/tproxy@latest

Or use docker images:

$ 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>

For 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>

On Windows, you can use scoop:

$ scoop install tproxy

Usages

$ 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)

Examples

Monitor gRPC connections

$ tproxy -p 8088 -r localhost:8081 -t grpc -d 100ms
  • listen on localhost and port 8088
  • redirect the traffic to localhost:8081
  • protocol type to be gRPC
  • delay 100ms for each packets

image

Monitor MySQL connections

$ tproxy -p 3307 -r localhost:3306

image

Check the connection reliability (Retrans rate and RTT)

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

image

Learn the connection pool behaviors

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

image

Give a Star! ⭐

If you like or are using this project, please give it a star. Thanks!

scripts

  • docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 -d mysql

  • docker search docker-oracle-xe-11g

  • docker run -h oracle --name oracle -d -p 15210:22 -p 15211:1521 -p 15213:8080 deepdiver/docker-oracle-xe-11g

  • %connect oracle://system:oracle@127.0.0.1:15211/xe

  • docker run -h oracle --name oracle -d -p 15210:22 -p 15211:1521 -p 15213:8080 epiclabs/docker-oracle-xe-11g

  • https://hub.docker.com/r/pengbai/docker-oracle-xe-11g-r2

  • oracle xe 11g r2 with sql initdb and web console

  • docker run -d -p 8080:8080 -p 1521:1521 pengbai/docker-oracle-xe-11g-r2

TODO

  • 服务端 tproxy -p :29200 -P 127.0.0.01:19200 -t http 客户端 poc olivere-es 时 不能正常打印响应体 olivere-es -U http://127.0.0.1:29200 -n 2 --trace, 客户端 gurl 时正常打印 gurl 'name=@姓名' 'sex=@random(男,女)' 'addr=@地址' 'idcard=@身份证' :29200/person/_doc/@ksuid -prU

About

A cli tool to proxy and analyze TCP connections.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 98.9%
  • Dockerfile 1.1%