fix
This commit is contained in:
parent
347cfdeaef
commit
60f6f58e69
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"fusenapi/server/websocket/internal/svc"
|
"fusenapi/server/websocket/internal/svc"
|
||||||
|
@ -42,23 +43,10 @@ func (l *GetStatLogic) GetStat(req *types.GetStatReq, userinfo *auth.UserInfo) (
|
||||||
currentCombineApiCount := 0
|
currentCombineApiCount := 0
|
||||||
currentUnityHandleCount := 0
|
currentUnityHandleCount := 0
|
||||||
combineErrorCount := 0
|
combineErrorCount := 0
|
||||||
lenUserList := len(req.UserKey)
|
req.UserKeys = strings.Trim(req.UserKeys, " ")
|
||||||
switch lenUserList {
|
if req.UserKeys != "" { //指定用户群体
|
||||||
case 0: //遍历所有
|
reqUserList := strings.Split(req.UserKeys, ",")
|
||||||
mapUserWsStat.Range(func(key, value any) bool {
|
for _, key := range reqUserList {
|
||||||
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 {
|
|
||||||
value, ok := mapUserWsStat.Load(key)
|
value, ok := mapUserWsStat.Load(key)
|
||||||
if ok { //存在就累加
|
if ok { //存在就累加
|
||||||
if stat, ok := value.(mapUserWsStatItem); ok {
|
if stat, ok := value.(mapUserWsStatItem); ok {
|
||||||
|
@ -72,8 +60,20 @@ func (l *GetStatLogic) GetStat(req *types.GetStatReq, userinfo *auth.UserInfo) (
|
||||||
}
|
}
|
||||||
userStat[key] = mapUserWsStatItem{}
|
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{
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetStatRsp{
|
||||||
WsTotalCount: currentWebsocketConnectCount,
|
WsTotalCount: currentWebsocketConnectCount,
|
||||||
CurCombineCount: currentCombineApiCount,
|
CurCombineCount: currentCombineApiCount,
|
||||||
|
|
|
@ -30,8 +30,8 @@ type CloseWebsocketReq struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetStatReq struct {
|
type GetStatReq struct {
|
||||||
Password string `form:"password"`
|
Password string `form:"password"`
|
||||||
UserKey []string `form:"user_key,optional"`
|
UserKeys string `form:"user_keys,optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetStatRsp struct {
|
type GetStatRsp struct {
|
||||||
|
|
|
@ -52,8 +52,8 @@ type CloseWebsocketReq {
|
||||||
}
|
}
|
||||||
//获取ws统计信息
|
//获取ws统计信息
|
||||||
type GetStatReq {
|
type GetStatReq {
|
||||||
Password string `form:"password"`
|
Password string `form:"password"`
|
||||||
UserKey []string `form:"user_key,optional"`
|
UserKeys string `form:"user_keys,optional"`
|
||||||
}
|
}
|
||||||
type GetStatRsp {
|
type GetStatRsp {
|
||||||
WsTotalCount int `json:"ws_total_count"` //ws连接总数
|
WsTotalCount int `json:"ws_total_count"` //ws连接总数
|
||||||
|
|
Loading…
Reference in New Issue
Block a user