Merge pull request #13372 from lafirest/fix/gateway_license

fix: limit gateway connections with license
This commit is contained in:
lafirest 2024-07-01 18:46:05 +08:00 committed by GitHub
commit 6c665037de
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 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

View File

@ -0,0 +1 @@
Fixed that the license did not count the number of gateway connections