Merge pull request #7771 from DDDHuang/monitor_topics

fix: monitor samplers data calculate topics error
This commit is contained in:
DDDHuang 2022-04-26 17:23:14 +08:00 committed by GitHub
commit 1185f010ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 8 deletions

View File

@ -237,9 +237,19 @@ merge_cluster_samplers(TS, NodeData, Cluster) ->
undefined -> undefined ->
Cluster#{TS => NodeData}; Cluster#{TS => NodeData};
ClusterData -> ClusterData ->
Cluster#{TS => count_map(NodeData, ClusterData)} Cluster#{TS => merge_cluster_sampler_map(NodeData, ClusterData)}
end. end.
merge_cluster_sampler_map(M1, M2) ->
Fun =
fun
(topics, Map) ->
Map;
(Key, Map) ->
Map#{Key => maps:get(Key, M1) + maps:get(Key, M2)}
end,
lists:foldl(Fun, #{}, ?SAMPLER_LIST).
merge_cluster_rate(Node, Cluster) -> merge_cluster_rate(Node, Cluster) ->
Fun = Fun =
fun(Key, Value, NCluster) -> fun(Key, Value, NCluster) ->
@ -365,13 +375,6 @@ internal_format(List) when is_list(List) ->
internal_format(#emqx_monit{time = Time, data = Data}) -> internal_format(#emqx_monit{time = Time, data = Data}) ->
#{Time => Data}. #{Time => Data}.
count_map(M1, M2) ->
Fun =
fun(Key, Map) ->
Map#{Key => maps:get(Key, M1) + maps:get(Key, M2)}
end,
lists:foldl(Fun, #{}, ?SAMPLER_LIST).
getstats(Key) -> getstats(Key) ->
%% Stats ets maybe not exist when ekka join. %% Stats ets maybe not exist when ekka join.
try try