fix: limit gateway connections with license

This commit is contained in:
firest 2024-06-30 20:06:04 +08:00
parent 2c48d7e0f0
commit b5d507bad8
3 changed files with 22 additions and 3 deletions

View File

@ -28,7 +28,7 @@
unregister_channel/2
]).
-export([lookup_channels/2]).
-export([lookup_channels/2, get_connected_client_count/0]).
-export([tabname/1]).
@ -95,6 +95,24 @@ lookup_channels(Name, ClientId) ->
record(ClientId, ChanPid) ->
#channel{chid = ClientId, pid = ChanPid}.
get_connected_client_count() ->
Gatewyas = emqx_gateway_utils:find_gateway_definitions(),
Fun = fun(#{name := Name}, Acc) ->
Tab = tabname(Name),
case ets:whereis(Tab) of
undefined ->
Acc;
_ ->
case ets:info(Tab, size) of
undefined ->
Acc;
Size ->
Acc + Size
end
end
end,
lists:foldl(Fun, 0, Gatewyas).
%%--------------------------------------------------------------------
%% gen_server callbacks
%%--------------------------------------------------------------------

View File

@ -3,6 +3,6 @@
{vsn, "5.1.0"},
{modules, []},
{registered, [emqx_license_sup]},
{applications, [kernel, stdlib, emqx_ctl]},
{applications, [kernel, stdlib, emqx_ctl, emqx_gateway]},
{mod, {emqx_license_app, []}}
]}.

View File

@ -56,7 +56,8 @@ local_connection_count() ->
-spec connection_count() -> non_neg_integer().
connection_count() ->
local_connection_count() + cached_remote_connection_count().
local_connection_count() + cached_remote_connection_count() +
emqx_gateway_cm_registry:get_connected_client_count().
%%------------------------------------------------------------------------------
%% gen_server callbacks