derp: add per-reason packet drop counter.

In parallel with the summed counter for now, for dashboard migration.

Signed-off-by: David Anderson <dave@natulte.net>
pull/203/head
David Anderson 5 years ago committed by Dave Anderson
parent 1e031001db
commit 58b8ebd290

@ -47,16 +47,22 @@ type Server struct {
logf logger.Logf logf logger.Logf
// Counters: // Counters:
packetsSent, bytesSent expvar.Int packetsSent, bytesSent expvar.Int
packetsRecv, bytesRecv expvar.Int packetsRecv, bytesRecv expvar.Int
packetsDropped expvar.Int packetsDropped expvar.Int
accepts expvar.Int packetsDroppedReason metrics.LabelMap
curClients expvar.Int packetsDroppedUnknown *expvar.Int
curHomeClients expvar.Int // ones with preferred packetsDroppedGone *expvar.Int
clientsReplaced expvar.Int packetsDroppedQueueHead *expvar.Int
unknownFrames expvar.Int packetsDroppedQueueTail *expvar.Int
homeMovesIn expvar.Int // established clients announce home server moves in packetsDroppedWrite *expvar.Int
homeMovesOut expvar.Int // established clients announce home server moves out accepts expvar.Int
curClients expvar.Int
curHomeClients expvar.Int // ones with preferred
clientsReplaced 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
@ -81,13 +87,19 @@ type Conn interface {
// Connections are given to it via Server.Accept. // Connections are given to it via Server.Accept.
func NewServer(privateKey key.Private, logf logger.Logf) *Server { func NewServer(privateKey key.Private, logf logger.Logf) *Server {
s := &Server{ s := &Server{
privateKey: privateKey, privateKey: privateKey,
publicKey: privateKey.Public(), publicKey: privateKey.Public(),
logf: logf, logf: logf,
clients: make(map[key.Public]*sclient), packetsDroppedReason: metrics.LabelMap{Label: "reason"},
clientsEver: make(map[key.Public]bool), clients: make(map[key.Public]*sclient),
netConns: make(map[Conn]chan struct{}), clientsEver: make(map[key.Public]bool),
} netConns: make(map[Conn]chan struct{}),
}
s.packetsDroppedUnknown = s.packetsDroppedReason.Get("unknown_dest")
s.packetsDroppedGone = s.packetsDroppedReason.Get("gone")
s.packetsDroppedQueueHead = s.packetsDroppedReason.Get("queue_head")
s.packetsDroppedQueueTail = s.packetsDroppedReason.Get("queue_tail")
s.packetsDroppedWrite = s.packetsDroppedReason.Get("write_error")
return s return s
} }
@ -293,6 +305,7 @@ func (c *sclient) handleFrameSendPacket(ctx context.Context, ft frameType, fl ui
if dst == nil { if dst == nil {
s.packetsDropped.Add(1) s.packetsDropped.Add(1)
s.packetsDroppedUnknown.Add(1)
if debug { if debug {
c.logf("dropping packet for unknown %x", dstKey) c.logf("dropping packet for unknown %x", dstKey)
} }
@ -303,6 +316,7 @@ func (c *sclient) handleFrameSendPacket(ctx context.Context, ft frameType, fl ui
defer dst.mu.RUnlock() defer dst.mu.RUnlock()
if dst.sendQueue == nil { if dst.sendQueue == nil {
s.packetsDropped.Add(1) s.packetsDropped.Add(1)
s.packetsDroppedGone.Add(1)
if debug { if debug {
c.logf("dropping packet for shutdown client %x", dstKey) c.logf("dropping packet for shutdown client %x", dstKey)
} }
@ -327,6 +341,7 @@ func (c *sclient) handleFrameSendPacket(ctx context.Context, ft frameType, fl ui
select { select {
case <-dst.sendQueue: case <-dst.sendQueue:
s.packetsDropped.Add(1) s.packetsDropped.Add(1)
s.packetsDroppedQueueHead.Add(1)
if debug { if debug {
c.logf("dropping packet from client %x queue head", dstKey) c.logf("dropping packet from client %x queue head", dstKey)
} }
@ -337,6 +352,7 @@ func (c *sclient) handleFrameSendPacket(ctx context.Context, ft frameType, fl ui
// contended queue with racing writers. Give up and tail-drop in // contended queue with racing writers. Give up and tail-drop in
// this case to keep reader unblocked. // this case to keep reader unblocked.
s.packetsDropped.Add(1) s.packetsDropped.Add(1)
s.packetsDroppedQueueTail.Add(1)
if debug { if debug {
c.logf("dropping packet from client %x queue tail", dstKey) c.logf("dropping packet from client %x queue tail", dstKey)
} }
@ -527,6 +543,7 @@ func (c *sclient) sendLoop(ctx context.Context) error {
break break
} }
c.s.packetsDropped.Add(1) c.s.packetsDropped.Add(1)
c.s.packetsDroppedGone.Add(1)
if debug { if debug {
c.logf("dropping packet for shutdown %x", c.key) c.logf("dropping packet for shutdown %x", c.key)
} }
@ -575,6 +592,7 @@ func (c *sclient) sendPacket(srcKey key.Public, contents []byte) (err error) {
// Stats update. // Stats update.
if err != nil { if err != nil {
c.s.packetsDropped.Add(1) c.s.packetsDropped.Add(1)
c.s.packetsDroppedWrite.Add(1)
if debug { if debug {
c.logf("dropping packet to %x: %v", c.key, err) c.logf("dropping packet to %x: %v", c.key, err)
} }
@ -624,6 +642,7 @@ func (s *Server) ExpVar() expvar.Var {
m.Set("bytes_received", &s.bytesRecv) m.Set("bytes_received", &s.bytesRecv)
m.Set("bytes_sent", &s.bytesSent) m.Set("bytes_sent", &s.bytesSent)
m.Set("packets_dropped", &s.packetsDropped) m.Set("packets_dropped", &s.packetsDropped)
m.Set("packets_dropped_reason", &s.packetsDroppedReason)
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)

Loading…
Cancel
Save