Merge pull request #3111 from emqx/issue#3109
Fix issue#3109 - remove the 'sessions.persistent.count', 'sessions.persistent.max' stats
This commit is contained in:
commit
a47a8f8010
|
@ -66,22 +66,26 @@
|
||||||
-type(stats() :: list({atom(), non_neg_integer()})).
|
-type(stats() :: list({atom(), non_neg_integer()})).
|
||||||
|
|
||||||
%% Connection stats
|
%% Connection stats
|
||||||
-define(CONNECTION_STATS, [
|
-define(CONNECTION_STATS,
|
||||||
'connections.count', % current connections
|
['connections.count', %% Count of Concurrent Connections
|
||||||
'connections.max' % maximum connections connected
|
'connections.max' %% Maximum Number of Concurrent Connections
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
%% Channel stats
|
||||||
|
-define(CHANNEL_STATS,
|
||||||
|
['channels.count', %% Count of Concurrent Channels
|
||||||
|
'channels.max' %% Maximum Number of Concurrent Channels
|
||||||
|
]).
|
||||||
|
|
||||||
%% Session stats
|
%% Session stats
|
||||||
-define(SESSION_STATS, [
|
-define(SESSION_STATS,
|
||||||
'sessions.count',
|
['sessions.count', %% Count of Concurrent Sessions
|
||||||
'sessions.max',
|
'sessions.max' %% Maximum Number of Concurrent Sessions
|
||||||
'sessions.persistent.count',
|
]).
|
||||||
'sessions.persistent.max'
|
|
||||||
]).
|
|
||||||
|
|
||||||
%% Subscribers, Subscriptions stats
|
%% PubSub stats
|
||||||
-define(PUBSUB_STATS, [
|
-define(PUBSUB_STATS,
|
||||||
'topics.count',
|
['topics.count',
|
||||||
'topics.max',
|
'topics.max',
|
||||||
'suboptions.count',
|
'suboptions.count',
|
||||||
'suboptions.max',
|
'suboptions.max',
|
||||||
|
@ -91,23 +95,24 @@
|
||||||
'subscriptions.max',
|
'subscriptions.max',
|
||||||
'subscriptions.shared.count',
|
'subscriptions.shared.count',
|
||||||
'subscriptions.shared.max'
|
'subscriptions.shared.max'
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-define(ROUTE_STATS, [
|
%% Route stats
|
||||||
'routes.count',
|
-define(ROUTE_STATS,
|
||||||
|
['routes.count',
|
||||||
'routes.max'
|
'routes.max'
|
||||||
]).
|
]).
|
||||||
|
|
||||||
%% Retained stats
|
%% Retained stats
|
||||||
-define(RETAINED_STATS, [
|
-define(RETAINED_STATS,
|
||||||
'retained.count',
|
['retained.count',
|
||||||
'retained.max'
|
'retained.max'
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-define(TAB, ?MODULE).
|
-define(TAB, ?MODULE).
|
||||||
-define(SERVER, ?MODULE).
|
-define(SERVER, ?MODULE).
|
||||||
|
|
||||||
-type opts() :: #{tick_ms := timeout()}.
|
-type(opts() :: #{tick_ms := timeout()}).
|
||||||
|
|
||||||
%% @doc Start stats server
|
%% @doc Start stats server
|
||||||
-spec(start_link() -> startlink_ret()).
|
-spec(start_link() -> startlink_ret()).
|
||||||
|
@ -122,7 +127,7 @@ start_link(Opts) ->
|
||||||
stop() ->
|
stop() ->
|
||||||
gen_server:call(?SERVER, stop, infinity).
|
gen_server:call(?SERVER, stop, infinity).
|
||||||
|
|
||||||
%% @doc Generate stats fun
|
%% @doc Generate stats fun.
|
||||||
-spec(statsfun(Stat :: atom()) -> fun()).
|
-spec(statsfun(Stat :: atom()) -> fun()).
|
||||||
statsfun(Stat) ->
|
statsfun(Stat) ->
|
||||||
fun(Val) -> setstat(Stat, Val) end.
|
fun(Val) -> setstat(Stat, Val) end.
|
||||||
|
@ -131,7 +136,7 @@ statsfun(Stat) ->
|
||||||
statsfun(Stat, MaxStat) ->
|
statsfun(Stat, MaxStat) ->
|
||||||
fun(Val) -> setstat(Stat, MaxStat, Val) end.
|
fun(Val) -> setstat(Stat, MaxStat, Val) end.
|
||||||
|
|
||||||
%% @doc Get all statistics
|
%% @doc Get all statistics.
|
||||||
-spec(getstats() -> stats()).
|
-spec(getstats() -> stats()).
|
||||||
getstats() ->
|
getstats() ->
|
||||||
case ets:info(?TAB, name) of
|
case ets:info(?TAB, name) of
|
||||||
|
@ -139,7 +144,7 @@ getstats() ->
|
||||||
_ -> ets:tab2list(?TAB)
|
_ -> ets:tab2list(?TAB)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% @doc Get stats by name
|
%% @doc Get stats by name.
|
||||||
-spec(getstat(atom()) -> maybe(non_neg_integer())).
|
-spec(getstat(atom()) -> maybe(non_neg_integer())).
|
||||||
getstat(Name) ->
|
getstat(Name) ->
|
||||||
case ets:lookup(?TAB, Name) of
|
case ets:lookup(?TAB, Name) of
|
||||||
|
@ -173,8 +178,7 @@ cancel_update(Name) ->
|
||||||
rec(Name, Secs, UpFun) ->
|
rec(Name, Secs, UpFun) ->
|
||||||
#update{name = Name, countdown = Secs, interval = Secs, func = UpFun}.
|
#update{name = Name, countdown = Secs, interval = Secs, func = UpFun}.
|
||||||
|
|
||||||
cast(Msg) ->
|
cast(Msg) -> gen_server:cast(?SERVER, Msg).
|
||||||
gen_server:cast(?SERVER, Msg).
|
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
|
@ -182,8 +186,13 @@ cast(Msg) ->
|
||||||
|
|
||||||
init(#{tick_ms := TickMs}) ->
|
init(#{tick_ms := TickMs}) ->
|
||||||
ok = emqx_tables:new(?TAB, [public, set, {write_concurrency, true}]),
|
ok = emqx_tables:new(?TAB, [public, set, {write_concurrency, true}]),
|
||||||
Stats = lists:append([?CONNECTION_STATS, ?SESSION_STATS, ?PUBSUB_STATS,
|
Stats = lists:append([?CONNECTION_STATS,
|
||||||
?ROUTE_STATS, ?RETAINED_STATS]),
|
?CHANNEL_STATS,
|
||||||
|
?SESSION_STATS,
|
||||||
|
?PUBSUB_STATS,
|
||||||
|
?ROUTE_STATS,
|
||||||
|
?RETAINED_STATS
|
||||||
|
]),
|
||||||
true = ets:insert(?TAB, [{Name, 0} || Name <- Stats]),
|
true = ets:insert(?TAB, [{Name, 0} || Name <- Stats]),
|
||||||
{ok, start_timer(#state{updates = [], tick_ms = TickMs}), hibernate}.
|
{ok, start_timer(#state{updates = [], tick_ms = TickMs}), hibernate}.
|
||||||
|
|
||||||
|
@ -211,16 +220,17 @@ handle_cast({setstat, Stat, MaxStat, Val}, State) ->
|
||||||
|
|
||||||
handle_cast({update_interval, Update = #update{name = Name}},
|
handle_cast({update_interval, Update = #update{name = Name}},
|
||||||
State = #state{updates = Updates}) ->
|
State = #state{updates = Updates}) ->
|
||||||
case lists:keyfind(Name, #update.name, Updates) of
|
NState = case lists:keyfind(Name, #update.name, Updates) of
|
||||||
#update{} ->
|
#update{} ->
|
||||||
?LOG(warning, "Duplicated update: ~s", [Name]),
|
?LOG(warning, "Duplicated update: ~s", [Name]),
|
||||||
{noreply, State};
|
State;
|
||||||
false ->
|
false -> State#state{updates = [Update|Updates]}
|
||||||
{noreply, State#state{updates = [Update | Updates]}}
|
end,
|
||||||
end;
|
{noreply, NState};
|
||||||
|
|
||||||
handle_cast({cancel_update, Name}, State = #state{updates = Updates}) ->
|
handle_cast({cancel_update, Name}, State = #state{updates = Updates}) ->
|
||||||
{noreply, State#state{updates = lists:keydelete(Name, #update.name, Updates)}};
|
Updates1 = lists:keydelete(Name, #update.name, Updates),
|
||||||
|
{noreply, State#state{updates = Updates1}};
|
||||||
|
|
||||||
handle_cast(Msg, State) ->
|
handle_cast(Msg, State) ->
|
||||||
?LOG(error, "Unexpected cast: ~p", [Msg]),
|
?LOG(error, "Unexpected cast: ~p", [Msg]),
|
||||||
|
@ -233,7 +243,7 @@ handle_info({timeout, TRef, tick}, State = #state{timer = TRef, updates = Update
|
||||||
try UpFun()
|
try UpFun()
|
||||||
catch
|
catch
|
||||||
_:Error ->
|
_:Error ->
|
||||||
?LOG(error, "update ~s failed: ~p", [Name, Error])
|
?LOG(error, "Update ~s failed: ~p", [Name, Error])
|
||||||
end,
|
end,
|
||||||
[Update#update{countdown = I} | Acc];
|
[Update#update{countdown = I} | Acc];
|
||||||
(Update = #update{countdown = C}, Acc) ->
|
(Update = #update{countdown = C}, Acc) ->
|
||||||
|
@ -259,10 +269,9 @@ safe_update_element(Key, Val) ->
|
||||||
try ets:update_element(?TAB, Key, {2, Val}) of
|
try ets:update_element(?TAB, Key, {2, Val}) of
|
||||||
false ->
|
false ->
|
||||||
ets:insert_new(?TAB, {Key, Val});
|
ets:insert_new(?TAB, {Key, Val});
|
||||||
true ->
|
true -> true
|
||||||
true
|
|
||||||
catch
|
catch
|
||||||
error:badarg ->
|
error:badarg ->
|
||||||
?LOG(warning, "Update ~p to ~p failed", [Key, Val])
|
?LOG(warning, "Failed to update ~p to ~p", [Key, Val])
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue