Coder Social home page Coder Social logo

kevwan / tproxy Goto Github PK

View Code? Open in Web Editor NEW
3.2K 30.0 223.0 1.66 MB

A cli tool to proxy and analyze TCP connections.

Home Page: https://go-zero.dev

License: MIT License

Dockerfile 2.04% Go 97.96%
monitoring-tool tcp tcpdump grpc proxy relay charles connection wireshark

tproxy's Introduction

tproxy

English | 简体中文

Go Go Report Card Release License: MIT

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/kevwan/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!

tproxy's People

Contributors

bingoohuang avatar chenquan avatar dependabot[bot] avatar jamlee avatar jiang4869 avatar kevwan avatar morciari avatar shaojunda avatar thushan avatar wuqinqiang avatar youjianglong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tproxy's Issues

Failed to start listener

Hi,
I just ran this command tproxy -p 3307 -r localhost:3306 and always get this output:
[x] Failed to start listener: failed to start listener: listen tcp: lookup localhost: no such host
I changed localhost to 127.0.0.1 but it still failed.

Is there a loop in the command?

I'm new to Docker and I'm confused when I try to understand the command

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>

I'm gonna split the command into 2 parts:

  1. docker run --rm -it -p <listen-port>:<listen-port> -p <remote-port>:<remote-port> kevinwan/tproxy:v1: The flag -p map 2 ports of the host to the container, that't alright;
  2. tproxy -l 0.0.0.0 -p <listen-port> -r host.docker.internal:<remote-port>: The -r host.docker.internal:<remote-port> part cause the container access the host port directly, which I think may cause a loop like this:

Docker 端口映射

Could you please help me to figure it out?

Nats msg bus

Hi,
what about to support/use Nats for the tcp proxy forwarding ?
Whit this approach it could be very easy to monitor the tcp traffic.

Bye,
Luca

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.