fix(gateway): sum the cluster connection data

This commit is contained in:
firest 2022-05-05 17:21:13 +08:00
parent db9cb6c4a0
commit f20f05161f
1 changed files with 16 additions and 3 deletions

View File

@ -116,11 +116,13 @@ gateways(Status) ->
], ],
GwInfo0 GwInfo0
), ),
NodeStatus = cluster_gateway_status(GwName),
{MaxCons, CurrCons} = sum_cluster_connections(NodeStatus),
GwInfo1#{ GwInfo1#{
max_connections => max_connections_count(Config), max_connections => MaxCons,
current_connections => current_connections_count(GwName), current_connections => CurrCons,
listeners => get_listeners_status(GwName, Config), listeners => get_listeners_status(GwName, Config),
node_status => cluster_gateway_status(GwName) node_status => NodeStatus
} }
end end
end, end,
@ -568,3 +570,14 @@ to_list(B) when is_binary(B) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Internal funcs %% Internal funcs
sum_cluster_connections(List) ->
sum_cluster_connections(List, 0, 0).
sum_cluster_connections(
[#{max_connections := Max, current_connections := Current} | T], MaxAcc, CurrAcc
) ->
sum_cluster_connections(T, MaxAcc + Max, Current + CurrAcc);
sum_cluster_connections([_ | T], MaxAcc, CurrAcc) ->
sum_cluster_connections(T, MaxAcc, CurrAcc);
sum_cluster_connections([], MaxAcc, CurrAcc) ->
{MaxAcc, CurrAcc}.