refactor(cli): Print listener ID as table head
This commit is contained in:
parent
2fc758c49a
commit
a93d62ace6
|
@ -510,21 +510,23 @@ trace_off(Who, Name) ->
|
||||||
|
|
||||||
listeners([]) ->
|
listeners([]) ->
|
||||||
foreach(fun({{Protocol, ListenOn}, _Pid}) ->
|
foreach(fun({{Protocol, ListenOn}, _Pid}) ->
|
||||||
Info = [{identifier, {string, emqx_listeners:find_id_by_listen_on(ListenOn)}},
|
Info = [{listen_on, {string, emqx_listeners:format_listen_on(ListenOn)}},
|
||||||
{acceptors, esockd:get_acceptors({Protocol, ListenOn})},
|
{acceptors, esockd:get_acceptors({Protocol, ListenOn})},
|
||||||
{max_conns, esockd:get_max_connections({Protocol, ListenOn})},
|
{max_conns, esockd:get_max_connections({Protocol, ListenOn})},
|
||||||
{current_conn, esockd:get_current_connections({Protocol, ListenOn})},
|
{current_conn, esockd:get_current_connections({Protocol, ListenOn})},
|
||||||
{shutdown_count, esockd:get_shutdown_count({Protocol, ListenOn})}
|
{shutdown_count, esockd:get_shutdown_count({Protocol, ListenOn})}
|
||||||
],
|
],
|
||||||
emqx_ctl:print("listener on ~s:~s~n", [Protocol, esockd:to_string(ListenOn)]),
|
emqx_ctl:print("~s~n", [listener_identifier(Protocol, ListenOn)]),
|
||||||
foreach(fun indent_print/1, Info)
|
foreach(fun indent_print/1, Info)
|
||||||
end, esockd:listeners()),
|
end, esockd:listeners()),
|
||||||
foreach(fun({Protocol, Opts}) ->
|
foreach(fun({Protocol, Opts}) ->
|
||||||
Info = [{acceptors, maps:get(num_acceptors, proplists:get_value(transport_options, Opts, #{}), 0)},
|
Port = proplists:get_value(port, Opts),
|
||||||
|
Info = [{listen_on, {string, emqx_listeners:format_listen_on(Port)}},
|
||||||
|
{acceptors, maps:get(num_acceptors, proplists:get_value(transport_options, Opts, #{}), 0)},
|
||||||
{max_conns, proplists:get_value(max_connections, Opts)},
|
{max_conns, proplists:get_value(max_connections, Opts)},
|
||||||
{current_conn, proplists:get_value(all_connections, Opts)},
|
{current_conn, proplists:get_value(all_connections, Opts)},
|
||||||
{shutdown_count, []}],
|
{shutdown_count, []}],
|
||||||
emqx_ctl:print("listener on ~s:~p~n", [Protocol, proplists:get_value(port, Opts)]),
|
emqx_ctl:print("~s~n", [listener_identifier(Protocol, Port)]),
|
||||||
foreach(fun indent_print/1, Info)
|
foreach(fun indent_print/1, Info)
|
||||||
end, ranch:info());
|
end, ranch:info());
|
||||||
|
|
||||||
|
@ -724,3 +726,11 @@ indent_print({Key, {string, Val}}) ->
|
||||||
emqx_ctl:print(" ~-16s: ~s~n", [Key, Val]);
|
emqx_ctl:print(" ~-16s: ~s~n", [Key, Val]);
|
||||||
indent_print({Key, Val}) ->
|
indent_print({Key, Val}) ->
|
||||||
emqx_ctl:print(" ~-16s: ~w~n", [Key, Val]).
|
emqx_ctl:print(" ~-16s: ~w~n", [Key, Val]).
|
||||||
|
|
||||||
|
listener_identifier(Protocol, ListenOn) ->
|
||||||
|
case emqx_listeners:find_id_by_listen_on(ListenOn) of
|
||||||
|
false ->
|
||||||
|
"http" ++ _ = atom_to_list(Protocol); %% assert
|
||||||
|
ID ->
|
||||||
|
ID
|
||||||
|
end.
|
||||||
|
|
|
@ -48,10 +48,10 @@
|
||||||
|
|
||||||
%% @doc Find listener identifier by listen-on.
|
%% @doc Find listener identifier by listen-on.
|
||||||
%% Return empty string (binary) if listener is not found in config.
|
%% Return empty string (binary) if listener is not found in config.
|
||||||
-spec(find_id_by_listen_on(esockd:listen_on()) -> binary()).
|
-spec(find_id_by_listen_on(esockd:listen_on()) -> binary() | false).
|
||||||
find_id_by_listen_on(ListenOn) ->
|
find_id_by_listen_on(ListenOn) ->
|
||||||
case find_by_listen_on(ListenOn) of
|
case find_by_listen_on(ListenOn) of
|
||||||
false -> <<>>;
|
false -> false;
|
||||||
L -> identifier(L)
|
L -> identifier(L)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -238,7 +238,7 @@ identifier(Proto, Name) when is_atom(Proto) ->
|
||||||
identifier(Proto, Name) ->
|
identifier(Proto, Name) ->
|
||||||
iolist_to_binary(["mqtt", ":", Proto, ":", Name]).
|
iolist_to_binary(["mqtt", ":", Proto, ":", Name]).
|
||||||
|
|
||||||
find_by_listen_on(ListenOn, []) -> error({unknown_listener, ListenOn});
|
find_by_listen_on(_ListenOn, []) -> false;
|
||||||
find_by_listen_on(ListenOn, [#{listen_on := ListenOn} = L | _]) -> L;
|
find_by_listen_on(ListenOn, [#{listen_on := ListenOn} = L | _]) -> L;
|
||||||
find_by_listen_on(ListenOn, [_ | Rest]) -> find_by_listen_on(ListenOn, Rest).
|
find_by_listen_on(ListenOn, [_ | Rest]) -> find_by_listen_on(ListenOn, Rest).
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue