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>
This commit is contained in:
David Anderson 2020-03-20 00:57:53 -07:00 committed by Dave Anderson
parent 1e031001db
commit 58b8ebd290
1 changed files with 35 additions and 16 deletions

View File

@ -50,6 +50,12 @@ type Server struct {
packetsSent, bytesSent expvar.Int
packetsRecv, bytesRecv expvar.Int
packetsDropped expvar.Int
packetsDroppedReason metrics.LabelMap
packetsDroppedUnknown *expvar.Int
packetsDroppedGone *expvar.Int
packetsDroppedQueueHead *expvar.Int
packetsDroppedQueueTail *expvar.Int
packetsDroppedWrite *expvar.Int
accepts expvar.Int
curClients expvar.Int
curHomeClients expvar.Int // ones with preferred
@ -84,10 +90,16 @@ func NewServer(privateKey key.Private, logf logger.Logf) *Server {
privateKey: privateKey,
publicKey: privateKey.Public(),
logf: logf,
packetsDroppedReason: metrics.LabelMap{Label: "reason"},
clients: make(map[key.Public]*sclient),
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
}
@ -293,6 +305,7 @@ func (c *sclient) handleFrameSendPacket(ctx context.Context, ft frameType, fl ui
if dst == nil {
s.packetsDropped.Add(1)
s.packetsDroppedUnknown.Add(1)
if debug {
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()
if dst.sendQueue == nil {
s.packetsDropped.Add(1)
s.packetsDroppedGone.Add(1)
if debug {
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 {
case <-dst.sendQueue:
s.packetsDropped.Add(1)
s.packetsDroppedQueueHead.Add(1)
if debug {
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
// this case to keep reader unblocked.
s.packetsDropped.Add(1)
s.packetsDroppedQueueTail.Add(1)
if debug {
c.logf("dropping packet from client %x queue tail", dstKey)
}
@ -527,6 +543,7 @@ func (c *sclient) sendLoop(ctx context.Context) error {
break
}
c.s.packetsDropped.Add(1)
c.s.packetsDroppedGone.Add(1)
if debug {
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.
if err != nil {
c.s.packetsDropped.Add(1)
c.s.packetsDroppedWrite.Add(1)
if debug {
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_sent", &s.bytesSent)
m.Set("packets_dropped", &s.packetsDropped)
m.Set("packets_dropped_reason", &s.packetsDroppedReason)
m.Set("packets_sent", &s.packetsSent)
m.Set("packets_received", &s.packetsRecv)
m.Set("unknown_frames", &s.unknownFrames)