From c59f7686967bbdce393ff218d5b56753bc2b1f6f Mon Sep 17 00:00:00 2001 From: cryptocifer Date: Mon, 27 Nov 2023 12:15:01 +0300 Subject: [PATCH] update --- metrics/connection.go | 11 +++++++++++ relay/wsserver.go | 3 +++ 2 files changed, 14 insertions(+) diff --git a/metrics/connection.go b/metrics/connection.go index 6d60fb3..c27ffab 100644 --- a/metrics/connection.go +++ b/metrics/connection.go @@ -30,6 +30,13 @@ var ( Name: "send_blockings", Help: "Number of send blocking connections", }) + + countMessageFromClosed = prometheus.NewCounter(prometheus.CounterOpts{ + Namespace: promNamespace, + Subsystem: promSubsystem, + Name: "sending_on_closed", + Help: "Number of sending on closed connections", + }) ) func IncNewConnection() { @@ -44,6 +51,10 @@ func IncSendBlocking() { countSendBlocking.Inc() } +func IncMessageFromClosed() { + countMessageFromClosed.Inc() +} + func SetCurrentConnections(num int) { gaugeCurrentConnections.Set(float64(num)) } diff --git a/relay/wsserver.go b/relay/wsserver.go index 203e0b7..4bc43f2 100644 --- a/relay/wsserver.go +++ b/relay/wsserver.go @@ -92,6 +92,9 @@ func (ws *WsServer) Run() { for { select { case message := <-ws.localCh: + if _, ok := ws.clients[message.client]; !ok { + metrics.IncMessageFromClosed() + } // local message could be "pub", "sub" or "ack" or "ping" // pub/sub message handler may contain time-consuming operations(e.g. read/write redis) // so put them in separate goroutine to avoid blocking wsserver main loop