upstats
This commit is contained in:
parent
5d4704acc2
commit
f2b0449117
|
@ -150,7 +150,8 @@ setstat(Stat, Val) ->
|
||||||
setstats(Stat, MaxStat, Val) ->
|
setstats(Stat, MaxStat, Val) ->
|
||||||
MaxVal = ets:lookup_element(?BROKER_TABLE, MaxStat, 2),
|
MaxVal = ets:lookup_element(?BROKER_TABLE, MaxStat, 2),
|
||||||
if
|
if
|
||||||
Val > MaxVal -> ets:update_element(?BROKER_TABLE, MaxStat, {2, Val});
|
Val > MaxVal ->
|
||||||
|
ets:update_element(?BROKER_TABLE, MaxStat, {2, Val});
|
||||||
true -> ok
|
true -> ok
|
||||||
end,
|
end,
|
||||||
ets:update_element(?BROKER_TABLE, Stat, {2, Val}).
|
ets:update_element(?BROKER_TABLE, Stat, {2, Val}).
|
||||||
|
|
|
@ -141,7 +141,7 @@ handle_cast({monitor, ClientId, Pid}, State = #state{tab = Tab}) ->
|
||||||
true -> ok;
|
true -> ok;
|
||||||
false -> lager:error("failed to monitor clientId '~s' with pid ~p", [ClientId, Pid])
|
false -> lager:error("failed to monitor clientId '~s' with pid ~p", [ClientId, Pid])
|
||||||
end,
|
end,
|
||||||
{noreply, State};
|
{noreply, setstats(State)};
|
||||||
|
|
||||||
handle_cast({unregister, ClientId, Pid}, State) ->
|
handle_cast({unregister, ClientId, Pid}, State) ->
|
||||||
case ets:lookup(?CLIENT_TABLE, ClientId) of
|
case ets:lookup(?CLIENT_TABLE, ClientId) of
|
||||||
|
|
|
@ -240,14 +240,22 @@ handle_cast(Msg, State) ->
|
||||||
|
|
||||||
%% a new record has been written.
|
%% a new record has been written.
|
||||||
handle_info({mnesia_table_event, {write, #topic_subscriber{subpid = Pid}, _ActivityId}}, State) ->
|
handle_info({mnesia_table_event, {write, #topic_subscriber{subpid = Pid}, _ActivityId}}, State) ->
|
||||||
|
%%TODO: rewrite...
|
||||||
erlang:monitor(process, Pid),
|
erlang:monitor(process, Pid),
|
||||||
{noreply, setstats(State)};
|
upstats(subscriber),
|
||||||
|
{noreply, State};
|
||||||
|
%% TODO:...
|
||||||
|
|
||||||
|
handle_info({mnesia_table_event, {write, #topic{}, _ActivityId}}, State) ->
|
||||||
|
upstats(topic),
|
||||||
|
{noreply, State};
|
||||||
|
|
||||||
%% {write, #topic{}, _ActivityId}
|
%% {write, #topic{}, _ActivityId}
|
||||||
%% {delete_object, _OldRecord, _ActivityId}
|
%% {delete_object, _OldRecord, _ActivityId}
|
||||||
%% {delete, {Tab, Key}, ActivityId}
|
%% {delete, {Tab, Key}, ActivityId}
|
||||||
handle_info({mnesia_table_event, _Event}, State) ->
|
handle_info({mnesia_table_event, _Event}, State) ->
|
||||||
{noreply, setstats(State)};
|
upstats(),
|
||||||
|
{noreply, State};
|
||||||
|
|
||||||
handle_info({'DOWN', _Mon, _Type, DownPid, _Info}, State) ->
|
handle_info({'DOWN', _Mon, _Type, DownPid, _Info}, State) ->
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
|
@ -260,7 +268,8 @@ handle_info({'DOWN', _Mon, _Type, DownPid, _Info}, State) ->
|
||||||
{atomic, _} -> ok;
|
{atomic, _} -> ok;
|
||||||
{aborted, Reason} -> lager:error("Failed to delete 'DOWN' subscriber ~p: ~p", [DownPid, Reason])
|
{aborted, Reason} -> lager:error("Failed to delete 'DOWN' subscriber ~p: ~p", [DownPid, Reason])
|
||||||
end,
|
end,
|
||||||
{noreply, setstats(State)};
|
upstats(),
|
||||||
|
{noreply, State};
|
||||||
|
|
||||||
handle_info(Info, State) ->
|
handle_info(Info, State) ->
|
||||||
lager:error("Unexpected Info: ~p", [Info]),
|
lager:error("Unexpected Info: ~p", [Info]),
|
||||||
|
@ -375,11 +384,16 @@ trie_delete_path([{NodeId, Word, _} | RestPath]) ->
|
||||||
throw({notfound, NodeId})
|
throw({notfound, NodeId})
|
||||||
end.
|
end.
|
||||||
|
|
||||||
setstats(State) ->
|
upstats() ->
|
||||||
emqttd_broker:setstat('topics/count', mnesia:table_info(topic, size)),
|
upstats(topic), upstats(subscribe).
|
||||||
|
|
||||||
|
upstats(topic) ->
|
||||||
|
emqttd_broker:setstat('topics/count', mnesia:table_info(topic, size));
|
||||||
|
|
||||||
|
upstats(subscribe) ->
|
||||||
emqttd_broker:setstats('subscribers/count',
|
emqttd_broker:setstats('subscribers/count',
|
||||||
'subscribers/max',
|
'subscribers/max',
|
||||||
mnesia:table_info(topic_subscriber, size)), State.
|
mnesia:table_info(topic_subscriber, size)).
|
||||||
|
|
||||||
dropped(true) ->
|
dropped(true) ->
|
||||||
emqttd_metrics:inc('messages/dropped');
|
emqttd_metrics:inc('messages/dropped');
|
||||||
|
|
Loading…
Reference in New Issue