This commit is contained in:
laodaming 2023-11-01 14:48:50 +08:00
parent 347cfdeaef
commit 60f6f58e69
3 changed files with 22 additions and 22 deletions

View File

@ -4,6 +4,7 @@ import (
"context"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"strings"
"sync"
"fusenapi/server/websocket/internal/svc"
@ -42,23 +43,10 @@ func (l *GetStatLogic) GetStat(req *types.GetStatReq, userinfo *auth.UserInfo) (
currentCombineApiCount := 0
currentUnityHandleCount := 0
combineErrorCount := 0
lenUserList := len(req.UserKey)
switch lenUserList {
case 0: //遍历所有
mapUserWsStat.Range(func(key, value any) bool {
if stat, ok := value.(mapUserWsStatItem); ok {
currentWebsocketConnectCount += stat.CurWsConnectCount
currentCombineApiCount += stat.CurCombineCount
currentUnityHandleCount += stat.CurUnityHandleCount
combineErrorCount += stat.CombineErrCount
} else {
logx.Error("断言mapUserWsStatItem错误")
}
userStat[key.(string)] = value
return true
})
default: //有指定用户
for _, key := range req.UserKey {
req.UserKeys = strings.Trim(req.UserKeys, " ")
if req.UserKeys != "" { //指定用户群体
reqUserList := strings.Split(req.UserKeys, ",")
for _, key := range reqUserList {
value, ok := mapUserWsStat.Load(key)
if ok { //存在就累加
if stat, ok := value.(mapUserWsStatItem); ok {
@ -72,8 +60,20 @@ func (l *GetStatLogic) GetStat(req *types.GetStatReq, userinfo *auth.UserInfo) (
}
userStat[key] = mapUserWsStatItem{}
}
} else { //不指定用户
mapUserWsStat.Range(func(key, value any) bool {
if stat, ok := value.(mapUserWsStatItem); ok {
currentWebsocketConnectCount += stat.CurWsConnectCount
currentCombineApiCount += stat.CurCombineCount
currentUnityHandleCount += stat.CurUnityHandleCount
combineErrorCount += stat.CombineErrCount
} else {
logx.Error("断言mapUserWsStatItem错误")
}
userStat[key.(string)] = value
return true
})
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetStatRsp{
WsTotalCount: currentWebsocketConnectCount,
CurCombineCount: currentCombineApiCount,

View File

@ -30,8 +30,8 @@ type CloseWebsocketReq struct {
}
type GetStatReq struct {
Password string `form:"password"`
UserKey []string `form:"user_key,optional"`
Password string `form:"password"`
UserKeys string `form:"user_keys,optional"`
}
type GetStatRsp struct {

View File

@ -52,8 +52,8 @@ type CloseWebsocketReq {
}
//获取ws统计信息
type GetStatReq {
Password string `form:"password"`
UserKey []string `form:"user_key,optional"`
Password string `form:"password"`
UserKeys string `form:"user_keys,optional"`
}
type GetStatRsp {
WsTotalCount int `json:"ws_total_count"` //ws连接总数