mirror of
https://github.com/tailscale/tailscale.git
synced 2025-01-08 09:07:44 +00:00
derp: add varz for home moves
Updates #162 Updates #163 (maybe) Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
8f0fd01efd
commit
5d8001d0ad
@ -51,6 +51,8 @@ type Server struct {
|
|||||||
curClients expvar.Int
|
curClients expvar.Int
|
||||||
curHomeClients expvar.Int // ones with preferred
|
curHomeClients expvar.Int // ones with preferred
|
||||||
unknownFrames expvar.Int
|
unknownFrames expvar.Int
|
||||||
|
homeMovesIn expvar.Int // established clients announce home server moves in
|
||||||
|
homeMovesOut expvar.Int // established clients announce home server moves out
|
||||||
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
closed bool
|
closed bool
|
||||||
@ -200,6 +202,7 @@ func (s *Server) accept(nc net.Conn, brw *bufio.ReadWriter) error {
|
|||||||
bw: bw,
|
bw: bw,
|
||||||
limiter: limiter,
|
limiter: limiter,
|
||||||
logf: logger.WithPrefix(s.logf, fmt.Sprintf("derp client %v/%x: ", nc.RemoteAddr(), clientKey)),
|
logf: logger.WithPrefix(s.logf, fmt.Sprintf("derp client %v/%x: ", nc.RemoteAddr(), clientKey)),
|
||||||
|
connectedAt: time.Now(),
|
||||||
}
|
}
|
||||||
if clientInfo != nil {
|
if clientInfo != nil {
|
||||||
c.info = *clientInfo
|
c.info = *clientInfo
|
||||||
@ -450,6 +453,7 @@ type sclient struct {
|
|||||||
info clientInfo
|
info clientInfo
|
||||||
logf logger.Logf
|
logf logger.Logf
|
||||||
limiter *rate.Limiter
|
limiter *rate.Limiter
|
||||||
|
connectedAt time.Time
|
||||||
|
|
||||||
keepAliveTimer *time.Timer
|
keepAliveTimer *time.Timer
|
||||||
keepAliveReset chan struct{}
|
keepAliveReset chan struct{}
|
||||||
@ -466,10 +470,23 @@ func (c *sclient) setPreferred(v bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.preferred = v
|
c.preferred = v
|
||||||
|
var homeMove *expvar.Int
|
||||||
if v {
|
if v {
|
||||||
c.s.curHomeClients.Add(1)
|
c.s.curHomeClients.Add(1)
|
||||||
|
homeMove = &c.s.homeMovesIn
|
||||||
} else {
|
} else {
|
||||||
c.s.curHomeClients.Add(-1)
|
c.s.curHomeClients.Add(-1)
|
||||||
|
homeMove = &c.s.homeMovesOut
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keep track of varz for home serve moves in/out. But ignore
|
||||||
|
// the initial packet set when a client connects, which we
|
||||||
|
// assume happens within 5 seconds. In any case, just for
|
||||||
|
// graphs, so not important to miss a move. But it shouldn't:
|
||||||
|
// the netcheck/re-STUNs in magicsock only happen about every
|
||||||
|
// 30 seconds.
|
||||||
|
if time.Since(c.connectedAt) > 5*time.Second {
|
||||||
|
homeMove.Add(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -528,5 +545,7 @@ func (s *Server) ExpVar() expvar.Var {
|
|||||||
m.Set("packets_sent", &s.packetsSent)
|
m.Set("packets_sent", &s.packetsSent)
|
||||||
m.Set("packets_received", &s.packetsRecv)
|
m.Set("packets_received", &s.packetsRecv)
|
||||||
m.Set("unknown_frames", &s.unknownFrames)
|
m.Set("unknown_frames", &s.unknownFrames)
|
||||||
|
m.Set("home_moves_in", &s.homeMovesIn)
|
||||||
|
m.Set("home_moves_out", &s.homeMovesOut)
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user