mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
prometheus
This commit is contained in:
parent
78ce5c3f69
commit
1cfa55817a
@ -39,6 +39,7 @@ func initPrometheus() {
|
||||
promePkg.NewGetNewestSeqTotalCounter()
|
||||
promePkg.NewPullMsgBySeqListTotalCounter()
|
||||
promePkg.NewMsgOnlinePushSuccessCounter()
|
||||
promePkg.NewOnlineUserCounter()
|
||||
//promePkg.NewSingleChatMsgRecvSuccessCounter()
|
||||
//promePkg.NewGroupChatMsgRecvSuccessCounter()
|
||||
//promePkg.NewWorkSuperGroupChatMsgRecvSuccessCounter()
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
promePkg "Open_IM/pkg/common/prometheus"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbRelay "Open_IM/pkg/proto/relay"
|
||||
@ -313,6 +314,7 @@ func (ws *WServer) addUserConn(uid string, platformID int, conn *UserConn, token
|
||||
for _, v := range ws.wsUserToConn {
|
||||
count = count + len(v)
|
||||
}
|
||||
promePkg.PromeGaugeInc(promePkg.OnlineUserGauge)
|
||||
log.Debug(operationID, "WS Add operation", "", "wsUser added", ws.wsUserToConn, "connection_uid", uid, "connection_platform", constant.PlatformIDToName(platformID), "online_user_num", len(ws.wsUserToConn), "online_conn_num", count)
|
||||
}
|
||||
|
||||
@ -352,6 +354,7 @@ func (ws *WServer) delUserConn(conn *UserConn) {
|
||||
if callbackResp.ErrCode != 0 {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "callbackUserOffline failed", callbackResp)
|
||||
}
|
||||
promePkg.PromeGaugeDec(promePkg.OnlineUserGauge)
|
||||
}
|
||||
|
||||
func (ws *WServer) getUserConn(uid string, platform int) *UserConn {
|
||||
|
@ -34,6 +34,7 @@ var (
|
||||
SingleChatMsgRecvSuccessCounter prometheus.Counter
|
||||
GroupChatMsgRecvSuccessCounter prometheus.Counter
|
||||
WorkSuperGroupChatMsgRecvSuccessCounter prometheus.Counter
|
||||
OnlineUserGauge prometheus.Gauge
|
||||
|
||||
//msg-msg
|
||||
SingleChatMsgProcessSuccessCounter prometheus.Counter
|
||||
@ -326,6 +327,16 @@ func NewWorkSuperGroupChatMsgRecvSuccessCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
func NewOnlineUserGauges() {
|
||||
if OnlineUserGauge != nil {
|
||||
return
|
||||
}
|
||||
OnlineUserGauge = promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "online_user_num",
|
||||
Help: "The number of online user num",
|
||||
})
|
||||
}
|
||||
|
||||
func NewSingleChatMsgProcessSuccessCounter() {
|
||||
if SingleChatMsgProcessSuccessCounter != nil {
|
||||
return
|
||||
|
@ -64,3 +64,19 @@ func PromeAdd(counter prometheus.Counter, add int) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func PromeGaugeInc(gauges prometheus.Gauge) {
|
||||
if config.Config.Prometheus.Enable {
|
||||
if gauges != nil {
|
||||
gauges.Inc()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func PromeGaugeDec(gauges prometheus.Gauge) {
|
||||
if config.Config.Prometheus.Enable {
|
||||
if gauges != nil {
|
||||
gauges.Dec()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user