mirror of
https://github.com/openziti/zrok.git
synced 2024-11-22 16:13:47 +01:00
'metricsConn' net.Conn wrapper to capture service metrics in the frontend (#74)
This commit is contained in:
parent
e58440722d
commit
d87e4ace67
@ -65,7 +65,11 @@ type zitiDialContext struct {
|
||||
|
||||
func (self *zitiDialContext) Dial(_ context.Context, _ string, addr string) (net.Conn, error) {
|
||||
svcName := strings.Split(addr, ":")[0] // ignore :port (we get passed 'host:port')
|
||||
return self.ctx.Dial(svcName)
|
||||
conn, err := self.ctx.Dial(svcName)
|
||||
if err != nil {
|
||||
return conn, err
|
||||
}
|
||||
return newMetricsConn(svcName, conn), nil
|
||||
}
|
||||
|
||||
func newServiceProxy(cfg *Config, ctx ziti.Context) (*httputil.ReverseProxy, error) {
|
||||
|
52
endpoints/frontend/metrics.go
Normal file
52
endpoints/frontend/metrics.go
Normal file
@ -0,0 +1,52 @@
|
||||
package frontend
|
||||
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
type metricsConn struct {
|
||||
id string
|
||||
conn net.Conn
|
||||
}
|
||||
|
||||
func newMetricsConn(id string, conn net.Conn) *metricsConn {
|
||||
return &metricsConn{id, conn}
|
||||
}
|
||||
|
||||
func (mc *metricsConn) Read(b []byte) (n int, err error) {
|
||||
n, err = mc.conn.Read(b)
|
||||
logrus.Infof("[%v] => %d", mc.id, n)
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (mc *metricsConn) Write(b []byte) (n int, err error) {
|
||||
n, err = mc.conn.Write(b)
|
||||
logrus.Infof("[%v] <= %d", mc.id, n)
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (mc *metricsConn) Close() error {
|
||||
return mc.conn.Close()
|
||||
}
|
||||
|
||||
func (mc *metricsConn) LocalAddr() net.Addr {
|
||||
return mc.conn.LocalAddr()
|
||||
}
|
||||
|
||||
func (mc *metricsConn) RemoteAddr() net.Addr {
|
||||
return mc.conn.RemoteAddr()
|
||||
}
|
||||
|
||||
func (mc *metricsConn) SetDeadline(t time.Time) error {
|
||||
return mc.conn.SetDeadline(t)
|
||||
}
|
||||
|
||||
func (mc *metricsConn) SetReadDeadline(t time.Time) error {
|
||||
return mc.conn.SetReadDeadline(t)
|
||||
}
|
||||
|
||||
func (mc *metricsConn) SetWriteDeadline(t time.Time) error {
|
||||
return mc.conn.SetWriteDeadline(t)
|
||||
}
|
Loading…
Reference in New Issue
Block a user