@@ -41,17 +41,18 @@ memory() ->
41
41
[aggregate (Names , Sums , memory , fun (X ) -> X end )
42
42
|| Names <- distinguished_interesting_sups ()],
43
43
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 ]),
55
56
56
57
[{total , Total },
57
58
{processes , Processes },
@@ -124,32 +125,53 @@ mnesia_memory() ->
124
125
_ -> 0
125
126
end .
126
127
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 )]).
129
130
130
131
ets_tables_memory (all ) ->
131
132
[{ets :info (T , name ), bytes (ets :info (T , memory ))}
132
133
|| T <- ets :all (),
133
134
is_atom (T )];
134
135
ets_tables_memory (OwnerName ) when is_atom (OwnerName ) ->
135
136
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 ),
138
142
[{ets :info (T , name ), bytes (ets :info (T , memory ))}
139
143
|| T <- ets :all (),
140
- lists :member (ets :info (T , owner ), Owners )].
144
+ lists :member (ets :info (T , owner ), OwnerPids )].
141
145
142
146
bytes (Words ) -> try
143
147
Words * erlang :system_info (wordsize )
144
148
catch
145
149
_ :_ -> 0
146
150
end .
147
- % % TODO: per-vhost supervisor
151
+
148
152
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 )).
150
172
151
173
interesting_sups0 () ->
152
- MsgIndexProcs = [ msg_store_transient_vhost , msg_store_persistent_vhost ] ,
174
+ MsgIndexProcs = msg_stores () ,
153
175
MgmtDbProcs = [rabbit_mgmt_sup_sup ],
154
176
PluginProcs = plugin_sups (),
155
177
[MsgIndexProcs , MgmtDbProcs , PluginProcs ].
@@ -166,18 +188,19 @@ ranch_server_sups() ->
166
188
error :badarg -> []
167
189
end .
168
190
169
- conn_sups ( With ) -> [{Sup , With } || Sup <- conn_sups () ].
191
+ with ( Sups , With ) -> [{Sup , With } || Sup <- Sups ].
170
192
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 ).
173
195
174
196
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 )]
181
204
++ interesting_sups0 ().
182
205
183
206
plugin_sups () ->
0 commit comments