monitor -> sysmon
This commit is contained in:
parent
de7ffc6bca
commit
5d4704acc2
|
@ -33,18 +33,19 @@
|
||||||
%% Application callbacks
|
%% Application callbacks
|
||||||
-export([start/2, stop/1]).
|
-export([start/2, stop/1]).
|
||||||
|
|
||||||
-define(SERVICES, [config,
|
%% Servers
|
||||||
event,
|
-define(SERVERS, [config,
|
||||||
client,
|
event,
|
||||||
session,
|
client,
|
||||||
pubsub,
|
session,
|
||||||
router,
|
pubsub,
|
||||||
broker,
|
router,
|
||||||
metrics,
|
broker,
|
||||||
bridge,
|
metrics,
|
||||||
auth,
|
bridge,
|
||||||
acl,
|
auth,
|
||||||
monitor]).
|
acl,
|
||||||
|
sysmon]).
|
||||||
|
|
||||||
-define(PRINT_MSG(Msg), io:format(Msg)).
|
-define(PRINT_MSG(Msg), io:format(Msg)).
|
||||||
|
|
||||||
|
@ -63,7 +64,7 @@ start(_StartType, _StartArgs) ->
|
||||||
print_banner(),
|
print_banner(),
|
||||||
emqttd_mnesia:start(),
|
emqttd_mnesia:start(),
|
||||||
{ok, Sup} = emqttd_sup:start_link(),
|
{ok, Sup} = emqttd_sup:start_link(),
|
||||||
start_services(Sup),
|
start_servers(Sup),
|
||||||
{ok, Listeners} = application:get_env(listen),
|
{ok, Listeners} = application:get_env(listen),
|
||||||
emqttd:open(Listeners),
|
emqttd:open(Listeners),
|
||||||
register(emqttd, self()),
|
register(emqttd, self()),
|
||||||
|
@ -78,63 +79,56 @@ print_vsn() ->
|
||||||
{ok, Desc} = application:get_key(description),
|
{ok, Desc} = application:get_key(description),
|
||||||
?PRINT("~s ~s is running now~n", [Desc, Vsn]).
|
?PRINT("~s ~s is running now~n", [Desc, Vsn]).
|
||||||
|
|
||||||
start_services(Sup) ->
|
start_servers(Sup) ->
|
||||||
lists:foreach(
|
Servers = lists:flatten([server(Srv) || Srv <- ?SERVERS]),
|
||||||
fun({Name, F}) when is_function(F) ->
|
[start_server(Sup, Server) || Server <- Servers].
|
||||||
?PRINT("~s is starting...", [Name]),
|
|
||||||
F(),
|
|
||||||
?PRINT_MSG("[done]~n");
|
|
||||||
({Name, Server}) ->
|
|
||||||
?PRINT("~s is starting...", [Name]),
|
|
||||||
start_child(Sup, Server),
|
|
||||||
?PRINT_MSG("[done]~n");
|
|
||||||
({Name, Server, Opts}) ->
|
|
||||||
?PRINT("~s is starting...", [ Name]),
|
|
||||||
start_child(Sup, Server, Opts),
|
|
||||||
?PRINT_MSG("[done]~n")
|
|
||||||
end, lists:flatten([service(Srv) || Srv <- ?SERVICES])).
|
|
||||||
|
|
||||||
service(config) ->
|
start_server(_Sup, {Name, F}) when is_function(F) ->
|
||||||
|
?PRINT("~s is starting...", [Name]),
|
||||||
|
F(),
|
||||||
|
?PRINT_MSG("[done]~n");
|
||||||
|
|
||||||
|
start_server(Sup, {Name, Server}) ->
|
||||||
|
?PRINT("~s is starting...", [Name]),
|
||||||
|
start_child(Sup, Server),
|
||||||
|
?PRINT_MSG("[done]~n");
|
||||||
|
|
||||||
|
start_server(Sup, {Name, Server, Opts}) ->
|
||||||
|
?PRINT("~s is starting...", [ Name]),
|
||||||
|
start_child(Sup, Server, Opts),
|
||||||
|
?PRINT_MSG("[done]~n").
|
||||||
|
|
||||||
|
%%TODO: redesign later...
|
||||||
|
server(config) ->
|
||||||
{"emqttd config", emqttd_config};
|
{"emqttd config", emqttd_config};
|
||||||
|
server(event) ->
|
||||||
service(event) ->
|
{"emqttd event", emqttd_event};
|
||||||
{"emqttd event", emqttd_event};
|
server(client) ->
|
||||||
|
|
||||||
service(client) ->
|
|
||||||
{"emqttd client manager", emqttd_cm};
|
{"emqttd client manager", emqttd_cm};
|
||||||
|
server(session) ->
|
||||||
service(session) ->
|
|
||||||
{ok, SessOpts} = application:get_env(session),
|
{ok, SessOpts} = application:get_env(session),
|
||||||
[{"emqttd session manager", emqttd_sm},
|
[{"emqttd session manager", emqttd_sm},
|
||||||
{"emqttd session supervisor", {supervisor, emqttd_session_sup}, SessOpts}];
|
{"emqttd session supervisor", {supervisor, emqttd_session_sup}, SessOpts}];
|
||||||
|
server(pubsub) ->
|
||||||
service(pubsub) ->
|
|
||||||
{"emqttd pubsub", emqttd_pubsub};
|
{"emqttd pubsub", emqttd_pubsub};
|
||||||
|
server(router) ->
|
||||||
service(router) ->
|
|
||||||
{"emqttd router", emqttd_router};
|
{"emqttd router", emqttd_router};
|
||||||
|
server(broker) ->
|
||||||
service(broker) ->
|
|
||||||
{ok, BrokerOpts} = application:get_env(broker),
|
{ok, BrokerOpts} = application:get_env(broker),
|
||||||
{"emqttd broker", emqttd_broker, BrokerOpts};
|
{"emqttd broker", emqttd_broker, BrokerOpts};
|
||||||
|
server(metrics) ->
|
||||||
service(metrics) ->
|
|
||||||
{ok, MetricOpts} = application:get_env(metrics),
|
{ok, MetricOpts} = application:get_env(metrics),
|
||||||
{"emqttd metrics", emqttd_metrics, MetricOpts};
|
{"emqttd metrics", emqttd_metrics, MetricOpts};
|
||||||
|
server(bridge) ->
|
||||||
service(bridge) ->
|
|
||||||
{"emqttd bridge supervisor", {supervisor, emqttd_bridge_sup}};
|
{"emqttd bridge supervisor", {supervisor, emqttd_bridge_sup}};
|
||||||
|
server(auth) ->
|
||||||
service(auth) ->
|
|
||||||
{ok, AuthMods} = application:get_env(auth),
|
{ok, AuthMods} = application:get_env(auth),
|
||||||
{"emqttd auth", emqttd_auth, AuthMods};
|
{"emqttd auth", emqttd_auth, AuthMods};
|
||||||
|
server(acl) ->
|
||||||
service(acl) ->
|
|
||||||
{ok, AclOpts} = application:get_env(acl),
|
{ok, AclOpts} = application:get_env(acl),
|
||||||
{"emqttd acl", emqttd_acl, AclOpts};
|
{"emqttd acl", emqttd_acl, AclOpts};
|
||||||
|
server(sysmon) ->
|
||||||
service(monitor) ->
|
{"emqttd system monitor", emqttd_sysmon}.
|
||||||
{"emqttd monitor", emqttd_monitor}.
|
|
||||||
|
|
||||||
start_child(Sup, {supervisor, Name}) ->
|
start_child(Sup, {supervisor, Name}) ->
|
||||||
supervisor:start_child(Sup, supervisor_spec(Name));
|
supervisor:start_child(Sup, supervisor_spec(Name));
|
||||||
|
@ -170,5 +164,3 @@ worker_spec(Name, Opts) ->
|
||||||
stop(_State) ->
|
stop(_State) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,14 +20,14 @@
|
||||||
%%% SOFTWARE.
|
%%% SOFTWARE.
|
||||||
%%%-----------------------------------------------------------------------------
|
%%%-----------------------------------------------------------------------------
|
||||||
%%% @doc
|
%%% @doc
|
||||||
%%% emqttd vm monitor.
|
%%% emqttd system monitor.
|
||||||
%%%
|
%%%
|
||||||
%%% @end
|
%%% @end
|
||||||
%%%-----------------------------------------------------------------------------
|
%%%-----------------------------------------------------------------------------
|
||||||
|
|
||||||
%%TODO: this is a demo module....
|
%%TODO: this is a demo module....
|
||||||
|
|
||||||
-module(emqttd_monitor).
|
-module(emqttd_sysmon).
|
||||||
|
|
||||||
-author('feng@emqtt.io').
|
-author('feng@emqtt.io').
|
||||||
|
|
||||||
|
@ -35,9 +35,10 @@
|
||||||
|
|
||||||
-export([start_link/0]).
|
-export([start_link/0]).
|
||||||
|
|
||||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
|
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||||
|
terminate/2, code_change/3]).
|
||||||
|
|
||||||
-record(state, {ok}).
|
-record(state, {}).
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% @doc
|
%% @doc
|
||||||
|
@ -58,8 +59,8 @@ init([]) ->
|
||||||
{ok, #state{}}.
|
{ok, #state{}}.
|
||||||
|
|
||||||
handle_call(Request, _From, State) ->
|
handle_call(Request, _From, State) ->
|
||||||
lager:error("unexpected request: ~p", [Request]),
|
lager:error("Unexpected request: ~p", [Request]),
|
||||||
{stop, {error, unexpected_request}, State}.
|
{reply, {error, unexpected_request}, State}.
|
||||||
|
|
||||||
handle_cast(Msg, State) ->
|
handle_cast(Msg, State) ->
|
||||||
lager:error("unexpected msg: ~p", [Msg]),
|
lager:error("unexpected msg: ~p", [Msg]),
|
||||||
|
@ -81,7 +82,7 @@ handle_info({monitor, SusPid, busy_port, Port}, State) ->
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
|
|
||||||
handle_info(Info, State) ->
|
handle_info(Info, State) ->
|
||||||
lager:error("unexpected info: ~p", [Info]),
|
lager:error("Unexpected info: ~p", [Info]),
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
terminate(_Reason, _State) ->
|
terminate(_Reason, _State) ->
|
Loading…
Reference in New Issue