로비 ccu metric 가져옴
This commit is contained in:
@ -79,8 +79,10 @@ func New(context context.Context, wsh *wshandler.WebsocketHandler) (*Tavern, err
|
||||
return tv, nil
|
||||
}
|
||||
|
||||
var ccu = metric.MetricWriterNil
|
||||
|
||||
func (tv *Tavern) Cleanup() {
|
||||
metric.ConcurrentUser.Set(0)
|
||||
ccu.Set(0)
|
||||
tv.mongoClient.Close()
|
||||
}
|
||||
|
||||
@ -118,6 +120,7 @@ func (tv *Tavern) prepare(ctx context.Context) error {
|
||||
tv.httpApiBorker.AddHandler(gocommon.MakeHttpApiHandler(instant, "instant"))
|
||||
tv.wsh.AddHandler(wshandler.MakeWebsocketApiHandler(instant, "instant"))
|
||||
|
||||
ccu = metric.NewMetric(metric.MetricGuage, "concurrent_user", "concurrent user count", map[string]string{"game": "lobby"})
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -138,7 +141,7 @@ func (tv *Tavern) LeaveChannel(ctx wshandler.ApiCallContext) {
|
||||
}
|
||||
|
||||
func (tv *Tavern) ClientConnected(conn *websocket.Conn, callby *wshandler.Sender) {
|
||||
metric.ConcurrentUser.Add(1)
|
||||
ccu.Add(1)
|
||||
tv.redison.Del(tv.redison.Context(), callby.Accid.Hex())
|
||||
_, err := tv.redison.JSONSet(callby.Accid.Hex(), "$", bson.M{"_ts": time.Now().UTC().Unix()})
|
||||
if err != nil {
|
||||
@ -147,7 +150,7 @@ func (tv *Tavern) ClientConnected(conn *websocket.Conn, callby *wshandler.Sender
|
||||
}
|
||||
|
||||
func (tv *Tavern) ClientDisconnected(msg string, callby *wshandler.Sender) {
|
||||
metric.ConcurrentUser.Add(-1)
|
||||
ccu.Add(-1)
|
||||
tv.redison.Del(tv.redison.Context(), callby.Accid.Hex()).Result()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user