derp: add varz for home moves

Updates #162
Updates #163 (maybe)

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
crawshaw/ipn
Brad Fitzpatrick 5 years ago committed by Brad Fitzpatrick
parent 8f0fd01efd
commit 5d8001d0ad

@ -51,6 +51,8 @@ type Server struct {
curClients expvar.Int
curHomeClients expvar.Int // ones with preferred
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
closed bool
@ -200,6 +202,7 @@ func (s *Server) accept(nc net.Conn, brw *bufio.ReadWriter) error {
bw: bw,
limiter: limiter,
logf: logger.WithPrefix(s.logf, fmt.Sprintf("derp client %v/%x: ", nc.RemoteAddr(), clientKey)),
connectedAt: time.Now(),
}
if clientInfo != nil {
c.info = *clientInfo
@ -450,6 +453,7 @@ type sclient struct {
info clientInfo
logf logger.Logf
limiter *rate.Limiter
connectedAt time.Time
keepAliveTimer *time.Timer
keepAliveReset chan struct{}
@ -466,10 +470,23 @@ func (c *sclient) setPreferred(v bool) {
return
}
c.preferred = v
var homeMove *expvar.Int
if v {
c.s.curHomeClients.Add(1)
homeMove = &c.s.homeMovesIn
} else {
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_received", &s.packetsRecv)
m.Set("unknown_frames", &s.unknownFrames)
m.Set("home_moves_in", &s.homeMovesIn)
m.Set("home_moves_out", &s.homeMovesOut)
return m
}

Loading…
Cancel
Save