diff --git a/internal/tun2/connection.go b/internal/tun2/connection.go index 9db2195..0490d6c 100644 --- a/internal/tun2/connection.go +++ b/internal/tun2/connection.go @@ -4,6 +4,7 @@ import ( "bufio" "bytes" "context" + "expvar" "io/ioutil" "net" "net/http" @@ -30,6 +31,8 @@ type Connection struct { detector *failure.Detector Auth *Auth usable bool + + counter *expvar.Int } func (c *Connection) cancel() { @@ -150,5 +153,7 @@ func (c *Connection) RoundTrip(req *http.Request) (*http.Response, error) { resp.Body = ioutil.NopCloser(bytes.NewBuffer(body)) resp.ContentLength = int64(len(body)) + c.counter.Add(1) + return resp, nil } diff --git a/internal/tun2/server.go b/internal/tun2/server.go index 54d5dbf..2d495ee 100644 --- a/internal/tun2/server.go +++ b/internal/tun2/server.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "errors" + "expvar" "fmt" "io" "io/ioutil" @@ -308,6 +309,7 @@ func (s *Server) HandleConn(c net.Conn, isKCP bool) { detector: failure.New(15, 1), Auth: auth, } + connection.counter = expvar.NewInt("http.backend." + connection.id + ".hits") defer func() { if r := recover(); r != nil {