Update copyright and format code
This commit is contained in:
parent
640c9287c2
commit
d93caa7c9e
|
@ -1,5 +1,5 @@
|
|||
%%--------------------------------------------------------------------
|
||||
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>.
|
||||
%% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
|
||||
%%
|
||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
%% you may not use this file except in compliance with the License.
|
||||
|
@ -16,6 +16,8 @@
|
|||
|
||||
-module(emqttd_cli).
|
||||
|
||||
-author("Feng Lee <feng@emqtt.io>").
|
||||
|
||||
-include("emqttd.hrl").
|
||||
|
||||
-include("emqttd_cli.hrl").
|
||||
|
@ -57,6 +59,7 @@ is_cmd(Fun) ->
|
|||
|
||||
%%--------------------------------------------------------------------
|
||||
%% @doc Node status
|
||||
|
||||
status([]) ->
|
||||
{InternalStatus, _ProvidedStatus} = init:get_status(),
|
||||
?PRINT("Node ~p is ~p~n", [node(), InternalStatus]),
|
||||
|
@ -71,6 +74,7 @@ status(_) ->
|
|||
|
||||
%%--------------------------------------------------------------------
|
||||
%% @doc Query broker
|
||||
|
||||
broker([]) ->
|
||||
Funs = [sysdescr, version, uptime, datetime],
|
||||
foreach(fun(Fun) ->
|
||||
|
@ -105,6 +109,7 @@ broker(_) ->
|
|||
|
||||
%%--------------------------------------------------------------------
|
||||
%% @doc Cluster with other nodes
|
||||
|
||||
cluster(["join", SNode]) ->
|
||||
case emqttd_cluster:join(emqttd_node:parse_name(SNode)) of
|
||||
ok ->
|
||||
|
@ -143,10 +148,12 @@ cluster(_) ->
|
|||
|
||||
%%--------------------------------------------------------------------
|
||||
%% @doc Users usage
|
||||
|
||||
users(Args) -> emq_auth_username:cli(Args).
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% @doc Query clients
|
||||
|
||||
clients(["list"]) ->
|
||||
dump(mqtt_client);
|
||||
|
||||
|
@ -169,14 +176,17 @@ if_client(ClientId, Fun) ->
|
|||
|
||||
%%--------------------------------------------------------------------
|
||||
%% @doc Sessions Command
|
||||
|
||||
sessions(["list"]) ->
|
||||
dump(mqtt_local_session);
|
||||
|
||||
%% performance issue?
|
||||
|
||||
sessions(["list", "persistent"]) ->
|
||||
lists:foreach(fun print/1, ets:match_object(mqtt_local_session, {'_', '_', false, '_'}));
|
||||
|
||||
%% performance issue?
|
||||
|
||||
sessions(["list", "transient"]) ->
|
||||
lists:foreach(fun print/1, ets:match_object(mqtt_local_session, {'_', '_', true, '_'}));
|
||||
|
||||
|
@ -194,6 +204,7 @@ sessions(_) ->
|
|||
|
||||
%%--------------------------------------------------------------------
|
||||
%% @doc Routes Command
|
||||
|
||||
routes(["list"]) ->
|
||||
Routes = emqttd_router:dump(),
|
||||
foreach(fun print/1, Routes);
|
||||
|
@ -207,6 +218,7 @@ routes(_) ->
|
|||
|
||||
%%--------------------------------------------------------------------
|
||||
%% @doc Topics Command
|
||||
|
||||
topics(["list"]) ->
|
||||
lists:foreach(fun(Topic) -> ?PRINT("~s~n", [Topic]) end, emqttd:topics());
|
||||
|
||||
|
@ -260,14 +272,14 @@ subscriptions(_) ->
|
|||
{"subscriptions del <ClientId>", "Delete static subscriptions manually"},
|
||||
{"subscriptions del <ClientId> <Topic>", "Delete a static subscription manually"}]).
|
||||
|
||||
if_could_print(Tab, Fun) ->
|
||||
case mnesia:table_info(Tab, size) of
|
||||
Size when Size >= ?MAX_LIMIT ->
|
||||
?PRINT("Could not list, too many ~ss: ~p~n", [Tab, Size]);
|
||||
_Size ->
|
||||
Keys = mnesia:dirty_all_keys(Tab),
|
||||
foreach(fun(Key) -> Fun(ets:lookup(Tab, Key)) end, Keys)
|
||||
end.
|
||||
% if_could_print(Tab, Fun) ->
|
||||
% case mnesia:table_info(Tab, size) of
|
||||
% Size when Size >= ?MAX_LIMIT ->
|
||||
% ?PRINT("Could not list, too many ~ss: ~p~n", [Tab, Size]);
|
||||
% _Size ->
|
||||
% Keys = mnesia:dirty_all_keys(Tab),
|
||||
% foreach(fun(Key) -> Fun(ets:lookup(Tab, Key)) end, Keys)
|
||||
% end.
|
||||
|
||||
if_valid_qos(QoS, Fun) ->
|
||||
try list_to_integer(QoS) of
|
||||
|
@ -303,6 +315,7 @@ plugins(_) ->
|
|||
|
||||
%%--------------------------------------------------------------------
|
||||
%% @doc Bridges command
|
||||
|
||||
bridges(["list"]) ->
|
||||
foreach(fun({Node, Topic, _Pid}) ->
|
||||
?PRINT("bridge: ~s--~s-->~s~n", [node(), Topic, Node])
|
||||
|
@ -360,6 +373,7 @@ parse_opt(_Cmd, Opt, _Val) ->
|
|||
|
||||
%%--------------------------------------------------------------------
|
||||
%% @doc vm command
|
||||
|
||||
vm([]) ->
|
||||
vm(["all"]);
|
||||
|
||||
|
@ -398,6 +412,7 @@ vm(_) ->
|
|||
|
||||
%%--------------------------------------------------------------------
|
||||
%% @doc mnesia Command
|
||||
|
||||
mnesia([]) ->
|
||||
mnesia:system_info();
|
||||
|
||||
|
@ -406,6 +421,7 @@ mnesia(_) ->
|
|||
|
||||
%%--------------------------------------------------------------------
|
||||
%% @doc Trace Command
|
||||
|
||||
trace(["list"]) ->
|
||||
foreach(fun({{Who, Name}, LogFile}) ->
|
||||
?PRINT("trace ~s ~s -> ~s~n", [Who, Name, LogFile])
|
||||
|
@ -448,6 +464,7 @@ trace_off(Who, Name) ->
|
|||
|
||||
%%--------------------------------------------------------------------
|
||||
%% @doc Listeners Command
|
||||
|
||||
listeners([]) ->
|
||||
foreach(fun({{Protocol, ListenOn}, Pid}) ->
|
||||
Info = [{acceptors, esockd:get_acceptors(Pid)},
|
||||
|
|
Loading…
Reference in New Issue