fix
This commit is contained in:
parent
347cfdeaef
commit
60f6f58e69
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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连接总数
|
||||
|
|
Loading…
Reference in New Issue
Block a user