fix
This commit is contained in:
parent
91b45e3595
commit
347cfdeaef
|
@ -41,24 +41,39 @@ func (l *GetStatLogic) GetStat(req *types.GetStatReq, userinfo *auth.UserInfo) (
|
|||
currentWebsocketConnectCount := 0
|
||||
currentCombineApiCount := 0
|
||||
currentUnityHandleCount := 0
|
||||
mapUserWsStat.Range(func(key, value any) bool {
|
||||
statData, ok := mapUserWsStat.Load(key)
|
||||
if ok { //存在就累加
|
||||
if stat, ok := statData.(mapUserWsStatItem); ok {
|
||||
//连接数等于0的用户就不返回
|
||||
if stat.CurWsConnectCount == 0 {
|
||||
return true
|
||||
}
|
||||
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 {
|
||||
value, ok := mapUserWsStat.Load(key)
|
||||
if ok { //存在就累加
|
||||
if stat, ok := value.(mapUserWsStatItem); ok {
|
||||
currentWebsocketConnectCount += stat.CurWsConnectCount
|
||||
currentCombineApiCount += stat.CurCombineCount
|
||||
currentUnityHandleCount += stat.CurUnityHandleCount
|
||||
combineErrorCount += stat.CombineErrCount
|
||||
} else {
|
||||
logx.Error("断言mapUserWsStatItem错误")
|
||||
}
|
||||
}
|
||||
userStat[key] = mapUserWsStatItem{}
|
||||
}
|
||||
userStat[key.(string)] = value
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetStatRsp{
|
||||
WsTotalCount: currentWebsocketConnectCount,
|
||||
CurCombineCount: currentCombineApiCount,
|
||||
|
|
|
@ -235,6 +235,8 @@ func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageRe
|
|||
res, err := w.logic.svcCtx.Repositories.ImageHandle.LogoCombine(w.logic.ctx, &combineReq)
|
||||
if err != nil {
|
||||
w.renderErrResponse(renderImageData.RequestId, renderImageData.RenderData.TemplateTag, "", "合成刀版图失败:"+err.Error(), renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId)
|
||||
//统计合图失败数
|
||||
increaseCombineRequestErrorCount(w.userId, w.guestId)
|
||||
logx.Error("合成刀版图失败,合成请求数据:", combineReq, "错误信息:", err)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -11,9 +11,10 @@ import (
|
|||
type websocketStatType string
|
||||
|
||||
const (
|
||||
TYPE_CUR_CONNECT_COUNT websocketStatType = "TYPE_CUR_CONNECT_COUNT" //ws连接数
|
||||
TYPE_CUR_COMBINE_IMAGE_COUNT websocketStatType = "TYPE_CUR_COMBINE_IMAGE_COUNT" //合图数
|
||||
TYPE_CUR_UNITY_HANDLE_COUNT websocketStatType = "TYPE_CUR_UNITY_HANDLE_COUNT" //unity处理数
|
||||
TYPE_CUR_CONNECT_COUNT websocketStatType = "TYPE_CUR_CONNECT_COUNT" //ws连接数
|
||||
TYPE_CUR_COMBINE_IMAGE_COUNT websocketStatType = "TYPE_CUR_COMBINE_IMAGE_COUNT" //合图数
|
||||
TYPE_CUR_COMBINE_IMAGE_ERR_COUNT websocketStatType = "TYPE_CUR_COMBINE_IMAGE_ERR_COUNT" //合图失败数
|
||||
TYPE_CUR_UNITY_HANDLE_COUNT websocketStatType = "TYPE_CUR_UNITY_HANDLE_COUNT" //unity处理数
|
||||
)
|
||||
|
||||
type websocketStatData struct {
|
||||
|
@ -24,6 +25,7 @@ type websocketStatData struct {
|
|||
}
|
||||
type mapUserWsStatItem struct {
|
||||
CurCombineCount int `json:"cur_combine_count"` //当前合图数
|
||||
CombineErrCount int `json:"combine_err_count"` //合图失败数
|
||||
CurWsConnectCount int `json:"cur_ws_connect_count"` //当前连接数
|
||||
CurUnityHandleCount int `json:"cur_unity_handle_count"` //当前unity处理数
|
||||
}
|
||||
|
@ -104,6 +106,23 @@ func decreaseCombineRequestCount(userId, guestId int64) {
|
|||
}
|
||||
}
|
||||
|
||||
// 累增合图失败数计数
|
||||
func increaseCombineRequestErrorCount(userId, guestId int64) {
|
||||
data := websocketStatData{
|
||||
UserId: userId,
|
||||
GuestId: guestId,
|
||||
Type: TYPE_CUR_COMBINE_IMAGE_ERR_COUNT,
|
||||
Num: 1,
|
||||
}
|
||||
select {
|
||||
case websocketStat <- data:
|
||||
return
|
||||
case <-time.After(time.Millisecond * 200):
|
||||
logx.Error("increaseCombineRequestErrorCount 输入管道超时,丢弃消息")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 累增unity请求数计数
|
||||
func increaseUnityRequestCount(userId, guestId int64) {
|
||||
data := websocketStatData{
|
||||
|
@ -210,6 +229,19 @@ func ConsumeWebsocketStatData(ctx context.Context) {
|
|||
}
|
||||
//保存统计
|
||||
mapUserWsStat.Store(key, stat)
|
||||
case TYPE_CUR_COMBINE_IMAGE_ERR_COUNT: //合图失败计数
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
//存在
|
||||
stat, ok := statData.(mapUserWsStatItem)
|
||||
if !ok {
|
||||
logx.Error("断言mapUserWsStatItem错误")
|
||||
continue
|
||||
}
|
||||
stat.CombineErrCount += data.Num
|
||||
//保存统计
|
||||
mapUserWsStat.Store(key, stat)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,12 +30,14 @@ type CloseWebsocketReq struct {
|
|||
}
|
||||
|
||||
type GetStatReq struct {
|
||||
Password string `form:"password"`
|
||||
Password string `form:"password"`
|
||||
UserKey []string `form:"user_key,optional"`
|
||||
}
|
||||
|
||||
type GetStatRsp struct {
|
||||
WsTotalCount int `json:"ws_total_count"` //ws连接总数
|
||||
CurCombineCount int `json:"cur_combine_count"` //合图任务数
|
||||
CombineErrorCount int `json:"combine_error_count"` //合图失败数
|
||||
CurUnityHandleCount int `json:"cur_unity_handle_count"` //当前unity请求总数
|
||||
UserWsStat interface{} `json:"user_ws_stat"` //用户连接统计
|
||||
}
|
||||
|
|
|
@ -52,11 +52,13 @@ type CloseWebsocketReq {
|
|||
}
|
||||
//获取ws统计信息
|
||||
type GetStatReq {
|
||||
Password string `form:"password"`
|
||||
Password string `form:"password"`
|
||||
UserKey []string `form:"user_key,optional"`
|
||||
}
|
||||
type GetStatRsp {
|
||||
WsTotalCount int `json:"ws_total_count"` //ws连接总数
|
||||
CurCombineCount int `json:"cur_combine_count"` //合图任务数
|
||||
CombineErrorCount int `json:"combine_error_count"` //合图失败数
|
||||
CurUnityHandleCount int `json:"cur_unity_handle_count"` //当前unity请求总数
|
||||
UserWsStat interface{} `json:"user_ws_stat"` //用户连接统计
|
||||
}
|
Loading…
Reference in New Issue
Block a user