Skip to content

Commit

Permalink
simplify sendbuf metric
Browse files Browse the repository at this point in the history
  • Loading branch information
windycrypto committed Nov 26, 2023
1 parent 12f3400 commit b906188
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions metrics/connection.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package metrics

import (
"strconv"
"github.com/prometheus/client_golang/prometheus"
)

Expand All @@ -25,12 +24,12 @@ var (
Help: "Number of current connections",
})

countSendBlocking = prometheus.NewCounterVec(prometheus.CounterOpts{
countSendBlocking = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: promNamespace,
Subsystem: promSubsystem,
Name: "send_blockings",
Help: "Number of send blocking connections",
}, []string{"sendbuflen"})
})
)

func IncNewConnection() {
Expand All @@ -41,9 +40,8 @@ func IncClosedConnection() {
countClosedConnections.Inc()
}

func IncSendBlocking(sendbufLen int) {
lenstr := strconv.Itoa(sendbufLen)
countSendBlocking.With(prometheus.Labels{"sendbuflen": lenstr}).Inc()
func IncSendBlocking() {
countSendBlocking.Inc()
}

func SetCurrentConnections(num int) {
Expand Down
2 changes: 1 addition & 1 deletion relay/wsconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (c *client) send(message SocketMessage) {
select {
case c.sendbuf <- message:
default:
metrics.IncSendBlocking(len(c.sendbuf))
metrics.IncSendBlocking()
log.Error("client sendbuf full", fmt.Errorf(""), zap.Any("client", c), zap.Any("len(sendbuf)", len(c.sendbuf)), zap.Any("message", message))
}
}
Expand Down

0 comments on commit b906188

Please sign in to comment.