fix systops
This commit is contained in:
parent
dc8b7f032e
commit
ca19a4e9e8
|
@ -31,20 +31,20 @@
|
||||||
%% $SYS Topics of Broker
|
%% $SYS Topics of Broker
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
-define(SYSTOP_BROKERS, [
|
-define(SYSTOP_BROKERS, [
|
||||||
version, % Broker version
|
version, % Broker version
|
||||||
uptime, % Broker uptime
|
uptime, % Broker uptime
|
||||||
timestamp, % Broker timestamp
|
datetime, % Broker local datetime
|
||||||
description % Broker description
|
description % Broker description
|
||||||
]).
|
]).
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% $SYS Topics of Clients
|
%% $SYS Topics of Clients
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
-define(SYSTOP_CLIENTS, [
|
-define(SYSTOP_CLIENTS, [
|
||||||
%'clients/connected',
|
|
||||||
%'clients/disconnected',
|
|
||||||
'clients/total', % total clients connected current
|
'clients/total', % total clients connected current
|
||||||
'clients/max' % max clients connected
|
'clients/max' % max clients connected
|
||||||
|
%'clients/connected',
|
||||||
|
%'clients/disconnected',
|
||||||
]).
|
]).
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
|
|
||||||
-export([start_link/1]).
|
-export([start_link/1]).
|
||||||
|
|
||||||
-export([version/0, uptime/0, description/0]).
|
-export([version/0, uptime/0, datetime/0, description/0]).
|
||||||
|
|
||||||
%% ------------------------------------------------------------------
|
%% ------------------------------------------------------------------
|
||||||
%% gen_server Function Exports
|
%% gen_server Function Exports
|
||||||
|
@ -69,6 +69,12 @@ description() ->
|
||||||
uptime() ->
|
uptime() ->
|
||||||
gen_server:call(?SERVER, uptime).
|
gen_server:call(?SERVER, uptime).
|
||||||
|
|
||||||
|
datetime() ->
|
||||||
|
{{Y, M, D}, {H, MM, S}} = calendar:local_time(),
|
||||||
|
lists:flatten(
|
||||||
|
io_lib:format(
|
||||||
|
"~4..0w-~2..0w-~2..0w ~2..0w:~2..0w:~2..0w", [Y, M, D, H, MM, S])).
|
||||||
|
|
||||||
%% ------------------------------------------------------------------
|
%% ------------------------------------------------------------------
|
||||||
%% gen_server Function Definitions
|
%% gen_server Function Definitions
|
||||||
%% ------------------------------------------------------------------
|
%% ------------------------------------------------------------------
|
||||||
|
@ -82,10 +88,8 @@ init([Options]) ->
|
||||||
[ets:insert(?TABLE, {Name, 0}) || Name <- ?SYSTOP_CLIENTS],
|
[ets:insert(?TABLE, {Name, 0}) || Name <- ?SYSTOP_CLIENTS],
|
||||||
[ets:insert(?TABLE, {Name, 0}) || Name <- ?SYSTOP_PUBSUB],
|
[ets:insert(?TABLE, {Name, 0}) || Name <- ?SYSTOP_PUBSUB],
|
||||||
% retain version, description
|
% retain version, description
|
||||||
retain(systop(version), list_to_binary(version())),
|
gen_server:cast(self(), prepare),
|
||||||
retain(systop(description), list_to_binary(description())),
|
{ok, tick(#state{started_at = os:timestamp(), sys_interval = SysInterval})}.
|
||||||
State = #state{started_at = os:timestamp(), sys_interval = SysInterval},
|
|
||||||
{ok, tick(State)}.
|
|
||||||
|
|
||||||
handle_call(uptime, _From, State) ->
|
handle_call(uptime, _From, State) ->
|
||||||
{reply, uptime(State), State};
|
{reply, uptime(State), State};
|
||||||
|
@ -93,14 +97,19 @@ handle_call(uptime, _From, State) ->
|
||||||
handle_call(_Request, _From, State) ->
|
handle_call(_Request, _From, State) ->
|
||||||
{reply, ok, State}.
|
{reply, ok, State}.
|
||||||
|
|
||||||
|
handle_cast(prepare, State) ->
|
||||||
|
retain(systop(version), list_to_binary(version())),
|
||||||
|
retain(systop(description), list_to_binary(description())),
|
||||||
|
{noreply, State};
|
||||||
|
|
||||||
handle_cast(_Msg, State) ->
|
handle_cast(_Msg, State) ->
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
handle_info(tick, State) ->
|
handle_info(tick, State) ->
|
||||||
publish(systop(uptime), list_to_binary(uptime(State))),
|
publish(systop(uptime), list_to_binary(uptime(State))),
|
||||||
[publish(systop(Name), i2b(Val)) || {Name, Val} <- ets:tab2list(?TABLE)],
|
publish(systop(datetime), list_to_binary(datetime())),
|
||||||
%%TODO... call emqtt_cm here?
|
%%TODO... call emqtt_cm here?
|
||||||
[publish(systop(client, Stat), i2b(Val)) || {Stat, Val} <- emqtt_cm:stats()],
|
[publish(systop(Stat), i2b(Val)) || {Stat, Val} <- emqtt_cm:stats()],
|
||||||
%%TODO... call emqtt_pubsub here?
|
%%TODO... call emqtt_pubsub here?
|
||||||
[publish(systop(Stat), i2b(Val)) || {Stat, Val} <- emqtt_cm:stats()],
|
[publish(systop(Stat), i2b(Val)) || {Stat, Val} <- emqtt_cm:stats()],
|
||||||
{noreply, tick(State)};
|
{noreply, tick(State)};
|
||||||
|
@ -117,10 +126,6 @@ code_change(_OldVsn, State, _Extra) ->
|
||||||
%% ------------------------------------------------------------------
|
%% ------------------------------------------------------------------
|
||||||
%% Internal Function Definitions
|
%% Internal Function Definitions
|
||||||
%% ------------------------------------------------------------------
|
%% ------------------------------------------------------------------
|
||||||
|
|
||||||
systop(Prefix, Name) ->
|
|
||||||
systop(list_to_atom(lists:concat([Prefix, '/', Name]))).
|
|
||||||
|
|
||||||
systop(Name) when is_atom(Name) ->
|
systop(Name) when is_atom(Name) ->
|
||||||
list_to_binary(lists:concat(["$SYS/brokers/", node(), "/", Name])).
|
list_to_binary(lists:concat(["$SYS/brokers/", node(), "/", Name])).
|
||||||
|
|
||||||
|
@ -161,4 +166,3 @@ tick(State = #state{sys_interval = SysInterval}) ->
|
||||||
i2b(I) when is_integer(I) ->
|
i2b(I) when is_integer(I) ->
|
||||||
list_to_binary(integer_to_list(I)).
|
list_to_binary(integer_to_list(I)).
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue