This commit is contained in:
laodaming 2023-11-01 15:43:25 +08:00
parent 537de58afc
commit 77066ec392
5 changed files with 41 additions and 5 deletions

View File

@ -61,6 +61,7 @@ func (l *GetStatLogic) GetStat(req *types.GetStatReq, userinfo *auth.UserInfo) (
CurCombineCount: curCombineTotalCount,
CurUnityHandleCount: curUnityHandleTotalCount,
CombineErrorCount: combineErrTotalCount,
UnityErrorCount: unityErrTotalCount,
UserWsStat: userStat,
})
}

View File

@ -49,10 +49,6 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a
logx.Error("渲染回调参数错误:任务标识")
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param task_id")
}
if req.Image == "" {
logx.Error("渲染回调参数错误:渲染结果图片数据")
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param image")
}
unityRenderEndTime := time.Now().UTC().UnixMilli()
//解析数据
var info websocket_data.ToUnityIdStruct
@ -121,6 +117,8 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a
}
//发送错误信息给前端
ws.renderErrResponse(requestId, info.TemplateTag, info.TaskId, "unity云渲染错误:"+req.Msg, 0, 0, 0, 0, 0, 0, 0)
//统计unity处理数
increaseUnityErrorCount(req.UserId, req.GuestId)
logx.Info("渲染失败且发送了失败信息")
} else {
logx.Info("渲染失败且找不到ws连接")

View File

@ -15,6 +15,7 @@ const (
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_UNITY_ERR_COUNT websocketStatType = "TYPE_UNITY_ERR_COUNT" //unity错误处理数
)
type websocketStatData struct {
@ -28,6 +29,7 @@ type mapUserWsStatItem struct {
CombineErrCount int `json:"combine_err_count"` //合图失败数
CurWsConnectCount int `json:"cur_ws_connect_count"` //当前连接数
CurUnityHandleCount int `json:"cur_unity_handle_count"` //当前unity处理数
UnityErrCount int `json:"unity_err_count"` //unity处理错误数
}
// 统计信息
@ -42,6 +44,8 @@ var (
combineErrTotalCount int
//unity正在渲染总数
curUnityHandleTotalCount int
//unity错误统计数
unityErrTotalCount int
//算法正在合图总数
curCombineTotalCount int
)
@ -155,7 +159,7 @@ func increaseUnityRequestCount(userId, guestId int64) {
curUnityHandleTotalCount += data.Num
return
case <-time.After(time.Millisecond * 200):
logx.Error("decreaseCombineRequestCount 输入管道超时,丢弃消息")
logx.Error("increaseUnityRequestCount 输入管道超时,丢弃消息")
return
}
}
@ -181,6 +185,24 @@ func decreaseUnityRequestCount(userId, guestId int64) {
}
}
// 累曾unity错误统计
func increaseUnityErrorCount(userId, guestId int64) {
data := websocketStatData{
UserId: userId,
GuestId: guestId,
Type: TYPE_UNITY_ERR_COUNT,
Num: 1,
}
select {
case websocketStat <- data:
unityErrTotalCount += data.Num
return
case <-time.After(time.Millisecond * 200):
logx.Error("increaseUnityErrorCount 输入管道超时,丢弃消息")
return
}
}
// 消费数据
func ConsumeWebsocketStatData(ctx context.Context) {
defer func() {
@ -266,6 +288,19 @@ func ConsumeWebsocketStatData(ctx context.Context) {
stat.CombineErrCount += data.Num
//保存统计
mapUserWsStat.Store(key, stat)
case TYPE_UNITY_ERR_COUNT: //unity错误信息
if !ok {
continue
}
//存在
stat, ok := statData.(mapUserWsStatItem)
if !ok {
logx.Error("断言mapUserWsStatItem错误")
continue
}
stat.UnityErrCount += data.Num
//保存统计
mapUserWsStat.Store(key, stat)
}
}
}

View File

@ -39,6 +39,7 @@ type GetStatRsp struct {
CurCombineCount int `json:"cur_combine_count"` //合图任务数
CombineErrorCount int `json:"combine_error_count"` //合图失败数
CurUnityHandleCount int `json:"cur_unity_handle_count"` //当前unity请求总数
UnityErrorCount int `json:"unity_error_count"` //unity错误统计
UserWsStat interface{} `json:"user_ws_stat"` //用户连接统计
}

View File

@ -60,5 +60,6 @@ type GetStatRsp {
CurCombineCount int `json:"cur_combine_count"` //合图任务数
CombineErrorCount int `json:"combine_error_count"` //合图失败数
CurUnityHandleCount int `json:"cur_unity_handle_count"` //当前unity请求总数
UnityErrorCount int `json:"unity_error_count"` //unity错误统计
UserWsStat interface{} `json:"user_ws_stat"` //用户连接统计
}