parent
187f878baf
commit
3bc92e5845
|
@ -26,6 +26,8 @@
|
||||||
, restart/0
|
, restart/0
|
||||||
, stop/0
|
, stop/0
|
||||||
, is_running/1
|
, is_running/1
|
||||||
|
, current_conns/2
|
||||||
|
, max_conns/2
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-export([ start_listener/1
|
-export([ start_listener/1
|
||||||
|
@ -89,6 +91,28 @@ is_running(quic, _ListenerId, _Conf)->
|
||||||
%% TODO: quic support
|
%% TODO: quic support
|
||||||
{error, no_found}.
|
{error, no_found}.
|
||||||
|
|
||||||
|
current_conns(ID, ListenOn) ->
|
||||||
|
{Type, Name} = parse_listener_id(ID),
|
||||||
|
current_conns(Type, Name, ListenOn).
|
||||||
|
|
||||||
|
current_conns(Type, Name, ListenOn) when Type == tcl; Type == ssl ->
|
||||||
|
esockd:get_current_connections({listener_id(Type, Name), ListenOn});
|
||||||
|
current_conns(Type, Name, _ListenOn) when Type =:= ws; Type =:= wss ->
|
||||||
|
proplists:get_value(all_connections, ranch:info(listener_id(Type, Name)));
|
||||||
|
current_conns(_, _, _) ->
|
||||||
|
{error, not_support}.
|
||||||
|
|
||||||
|
max_conns(ID, ListenOn) ->
|
||||||
|
{Type, Name} = parse_listener_id(ID),
|
||||||
|
max_conns(Type, Name, ListenOn).
|
||||||
|
|
||||||
|
max_conns(Type, Name, ListenOn) when Type == tcl; Type == ssl ->
|
||||||
|
esockd:get_max_connections({listener_id(Type, Name), ListenOn});
|
||||||
|
max_conns(Type, Name, _ListenOn) when Type =:= ws; Type =:= wss ->
|
||||||
|
proplists:get_value(max_connections, ranch:info(listener_id(Type, Name)));
|
||||||
|
max_conns(_, _, _) ->
|
||||||
|
{error, not_support}.
|
||||||
|
|
||||||
%% @doc Start all listeners.
|
%% @doc Start all listeners.
|
||||||
-spec(start() -> ok).
|
-spec(start() -> ok).
|
||||||
start() ->
|
start() ->
|
||||||
|
|
|
@ -412,26 +412,28 @@ trace_off(Who, Name) ->
|
||||||
%% @doc Listeners Command
|
%% @doc Listeners Command
|
||||||
|
|
||||||
listeners([]) ->
|
listeners([]) ->
|
||||||
lists:foreach(fun({{Protocol, ListenOn}, _Pid}) ->
|
lists:foreach(fun({ID, Conf}) ->
|
||||||
Info = [{listen_on, {string, format_listen_on(ListenOn)}},
|
{Host, Port} = maps:get(bind, Conf),
|
||||||
{acceptors, esockd:get_acceptors({Protocol, ListenOn})},
|
Acceptors = maps:get(acceptors, Conf),
|
||||||
{max_conns, esockd:get_max_connections({Protocol, ListenOn})},
|
ProxyProtocol = maps:get(proxy_protocol, Conf, undefined),
|
||||||
{current_conn, esockd:get_current_connections({Protocol, ListenOn})},
|
Running = maps:get(running, Conf),
|
||||||
{shutdown_count, esockd:get_shutdown_count({Protocol, ListenOn})}
|
CurrentConns = case emqx_listeners:current_conns(ID, {Host, Port}) of
|
||||||
],
|
{error, _} -> [];
|
||||||
emqx_ctl:print("~s~n", [Protocol]),
|
CC -> [{current_conn, CC}]
|
||||||
|
end,
|
||||||
|
MaxConn = case emqx_listeners:max_conns(ID, {Host, Port}) of
|
||||||
|
{error, _} -> [];
|
||||||
|
MC -> [{max_conns, MC}]
|
||||||
|
end,
|
||||||
|
Info = [
|
||||||
|
{listen_on, {string, format_listen_on(Port)}},
|
||||||
|
{acceptors, Acceptors},
|
||||||
|
{proxy_protocol, ProxyProtocol},
|
||||||
|
{running, Running}
|
||||||
|
] ++ CurrentConns ++ MaxConn,
|
||||||
|
emqx_ctl:print("~s~n", [ID]),
|
||||||
lists:foreach(fun indent_print/1, Info)
|
lists:foreach(fun indent_print/1, Info)
|
||||||
end, esockd:listeners()),
|
end, emqx_listeners:list());
|
||||||
lists:foreach(fun({Protocol, Opts}) ->
|
|
||||||
Port = proplists:get_value(port, Opts),
|
|
||||||
Info = [{listen_on, {string, format_listen_on(Port)}},
|
|
||||||
{acceptors, maps:get(num_acceptors, proplists:get_value(transport_options, Opts, #{}), 0)},
|
|
||||||
{max_conns, proplists:get_value(max_connections, Opts)},
|
|
||||||
{current_conn, proplists:get_value(all_connections, Opts)},
|
|
||||||
{shutdown_count, []}],
|
|
||||||
emqx_ctl:print("~s~n", [Protocol]),
|
|
||||||
lists:foreach(fun indent_print/1, Info)
|
|
||||||
end, ranch:info());
|
|
||||||
|
|
||||||
listeners(["stop", ListenerId]) ->
|
listeners(["stop", ListenerId]) ->
|
||||||
case emqx_listeners:stop_listener(list_to_atom(ListenerId)) of
|
case emqx_listeners:stop_listener(list_to_atom(ListenerId)) of
|
||||||
|
|
Loading…
Reference in New Issue