tun2: expvar counters for each backend

This commit is contained in:
Cadey Ratio 2017-10-07 09:41:48 -07:00
parent 0ffaa5110a
commit b4e80a6d9c
No known key found for this signature in database
GPG Key ID: D607EE27C2E7F89A
2 changed files with 7 additions and 0 deletions

View File

@ -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
}

View File

@ -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 {