Skip to content

Commit e4d6c27

Browse files
author
Daniil Fedotov
committed
Queue and msg store supervisor locations
1 parent 6cb3d32 commit e4d6c27

File tree

1 file changed

+51
-28
lines changed

1 file changed

+51
-28
lines changed

src/rabbit_vm.erl

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,18 @@ memory() ->
4141
[aggregate(Names, Sums, memory, fun (X) -> X end)
4242
|| Names <- distinguished_interesting_sups()],
4343

44-
Mnesia = mnesia_memory(),
45-
MsgIndexETS = ets_memory([msg_store_persistent_vhost, msg_store_transient_vhost]),
46-
MetricsETS = ets_memory([rabbit_metrics]),
47-
MetricsProc = try
48-
[{_, M}] = process_info(whereis(rabbit_metrics), [memory]),
49-
M
50-
catch
51-
error:badarg ->
52-
0
53-
end,
54-
MgmtDbETS = ets_memory([rabbit_mgmt_storage]),
44+
Mnesia = mnesia_memory(),
45+
MsgIndexETS = ets_memory(msg_stores()),
46+
MetricsETS = ets_memory([rabbit_metrics]),
47+
MetricsProc =
48+
try
49+
[{_, M}] = process_info(whereis(rabbit_metrics), [memory]),
50+
M
51+
catch
52+
error:badarg ->
53+
0
54+
end,
55+
MgmtDbETS = ets_memory([rabbit_mgmt_storage]),
5556

5657
[{total, Total},
5758
{processes, Processes},
@@ -124,32 +125,53 @@ mnesia_memory() ->
124125
_ -> 0
125126
end.
126127

127-
ets_memory(OwnerNames) ->
128-
lists:sum([V || {_K, V} <- ets_tables_memory(OwnerNames)]).
128+
ets_memory(Owners) ->
129+
lists:sum([V || {_K, V} <- ets_tables_memory(Owners)]).
129130

130131
ets_tables_memory(all) ->
131132
[{ets:info(T, name), bytes(ets:info(T, memory))}
132133
|| T <- ets:all(),
133134
is_atom(T)];
134135
ets_tables_memory(OwnerName) when is_atom(OwnerName) ->
135136
ets_tables_memory([OwnerName]);
136-
ets_tables_memory(OwnerNames) when is_list(OwnerNames) ->
137-
Owners = [whereis(N) || N <- OwnerNames],
137+
ets_tables_memory(Owners) when is_list(Owners) ->
138+
OwnerPids = lists:map(fun(O) when is_pid(O) -> O;
139+
(O) when is_atom(O) -> whereis(O)
140+
end,
141+
Owners),
138142
[{ets:info(T, name), bytes(ets:info(T, memory))}
139143
|| T <- ets:all(),
140-
lists:member(ets:info(T, owner), Owners)].
144+
lists:member(ets:info(T, owner), OwnerPids)].
141145

142146
bytes(Words) -> try
143147
Words * erlang:system_info(wordsize)
144148
catch
145149
_:_ -> 0
146150
end.
147-
%% TODO: per-vhost supervisor
151+
148152
interesting_sups() ->
149-
[[rabbit_amqqueue_sup_sup], conn_sups() | interesting_sups0()].
153+
[queue_sups(), conn_sups() | interesting_sups0()].
154+
155+
queue_sups() ->
156+
all_vhosts_children(rabbit_amqqueue_sup_sup).
157+
158+
msg_stores() ->
159+
all_vhosts_children(msg_store_transient)
160+
++
161+
all_vhosts_children(msg_store_persistent).
162+
163+
all_vhosts_children(Name) ->
164+
lists:filter_map(
165+
fun({_, VHostSup, _, _}) ->
166+
case supervisor2:find_child(VHostSup, Name) of
167+
[QSup] -> {true, QSup};
168+
[] -> false
169+
end
170+
end,
171+
supervisor:which_children(rabbit_vhost_sup_sup)).
150172

151173
interesting_sups0() ->
152-
MsgIndexProcs = [msg_store_transient_vhost, msg_store_persistent_vhost],
174+
MsgIndexProcs = msg_stores(),
153175
MgmtDbProcs = [rabbit_mgmt_sup_sup],
154176
PluginProcs = plugin_sups(),
155177
[MsgIndexProcs, MgmtDbProcs, PluginProcs].
@@ -166,18 +188,19 @@ ranch_server_sups() ->
166188
error:badarg -> []
167189
end.
168190

169-
conn_sups(With) -> [{Sup, With} || Sup <- conn_sups()].
191+
with(Sups, With) -> [{Sup, With} || Sup <- Sups].
170192

171-
distinguishers() -> [{rabbit_amqqueue_sup_sup, fun queue_type/1} |
172-
conn_sups(fun conn_type/1)].
193+
distinguishers() -> with(queue_sups(), fun queue_type/1) ++
194+
with(conn_sups(), fun conn_type/1).
173195

174196
distinguished_interesting_sups() ->
175-
[[{rabbit_amqqueue_sup_sup, master}],
176-
[{rabbit_amqqueue_sup_sup, slave}],
177-
conn_sups(reader),
178-
conn_sups(writer),
179-
conn_sups(channel),
180-
conn_sups(other)]
197+
[
198+
with(queue_sups(), master),
199+
with(queue_sups(), slave),
200+
with(conn_sups(), reader),
201+
with(conn_sups(), writer),
202+
with(conn_sups(), channel),
203+
with(conn_sups(), other)]
181204
++ interesting_sups0().
182205

183206
plugin_sups() ->

0 commit comments

Comments
 (0)