This commit is contained in:
laodaming
2023-10-20 15:14:41 +08:00
parent 6a9bfa0ef0
commit 6c341590ee
6 changed files with 26 additions and 18 deletions

View File

@@ -32,6 +32,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/api/websocket/close_websocket",
Handler: CloseWebsocketHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/api/websocket/get_stat",
Handler: GetStatHandler(serverCtx),
},
},
)
}

View File

@@ -321,15 +321,7 @@ func (w *wsConnectItem) heartbeat() {
if w.debug != nil && w.debug.Exp != nil && *w.debug.Exp < time.Now().UTC().Unix() {
w.debug = nil
}
//发送心跳信息
var d interface{}
if w.debug != nil {
d = websocket_data.HeartBeatMsg{
WsCount: currentWebsocketConnectCount,
CombineCount: currentRequestCombineApiCount,
}
}
if err := w.conn.WriteMessage(websocket.PongMessage, w.respondDataFormat(constants.WEBSOCKET_HEARTBEAT, d)); err != nil {
if err := w.conn.WriteMessage(websocket.PongMessage, nil); err != nil {
logx.Error("发送心跳信息异常,关闭连接:", w.uniqueId, err)
w.close()
return

View File

@@ -29,6 +29,15 @@ type CloseWebsocketReq struct {
Wid string `json:"wid"`
}
type GetStatReq struct {
Password string `form:"password"`
}
type GetStatRsp struct {
WsTotalCount int `json:"ws_total_count"` //ws连接数
CurRequestCombineCount int `json:"cur_request_combine_count"`
}
type Request struct {
}