Reputation: 3089
I have written an Erlang chat backend, using the cowboy module.
I'm trying to figure out how can i log the number of open web sockets connections, that are currently connected.
I have been looking for an answer to this question for a while, and i couldn't find one.
Do you have any idea how it could be done?
Thank you for your time,
Upvotes: 1
Views: 560
Reputation: 423
Do count your websocket into websocket_init
or websocket_handle
I write down the information of the public in websocket ets
table
Add information websocket about:
websocket_handle({text, Msg}, Req, State) ->
ets:insert(systbl_websockets, {self(), get_current, other_info}),
{reply, [{text, <<"ok">>}], Req, State, hibernate};
end;
Remove information websocket about:
websocket_terminate(_Reason, _Req, _State) ->
lager:debug("Close connection"),
ets:delete(systbl_websockets, self()),
{ok, _Req, _State, shutdown}.
Upvotes: 4