diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit.erl | 2 | ||||
| -rw-r--r-- | src/rabbit_misc.erl | 45 |
2 files changed, 46 insertions, 1 deletions
diff --git a/src/rabbit.erl b/src/rabbit.erl index 7a021e378d..3809c07943 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -356,7 +356,7 @@ status() -> {running_applications, application:which_applications(infinity)}, {os, os:type()}, {erlang_version, erlang:system_info(system_version)}, - {memory, erlang:memory()}], + {memory, rabbit_misc:memory()}], S2 = rabbit_misc:filter_exit_map( fun ({Key, {M, F, A}}) -> {Key, erlang:apply(M, F, A)} end, [{vm_memory_high_watermark, {vm_memory_monitor, diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index a0536a50a9..996d8ced76 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -63,6 +63,7 @@ -export([version/0]). -export([sequence_error/1]). -export([json_encode/1, json_decode/1, json_to_term/1, term_to_json/1]). +-export([memory/0]). %% Horrible macro to use in guards -define(IS_BENIGN_EXIT(R), @@ -987,3 +988,47 @@ term_to_json(L) when is_list(L) -> term_to_json(V) when is_binary(V) orelse is_number(V) orelse V =:= null orelse V =:= true orelse V =:= false -> V. + +%% Like erlang:memory(), but with awareness of rabbit-y things +memory() -> + QPids = lists:append([pids(Q) || Q <- rabbit_amqqueue:list()]), + Conns = sum_proc_memory(rabbit_networking:connections_local()), + Chs = sum_proc_memory(rabbit_channel:list_local()), + Qs = sum_proc_memory(QPids), + Mnesia = mnesia_memory(), + MsgIndex = ets_memory(rabbit_msg_store_ets_index), + [{total, erlang:memory(total)}, + {connection_procs, Conns}, + {channel_procs, Chs}, + {queue_procs, Qs}, + {other_procs, erlang:memory(processes) - Conns - Chs - Qs}, + {mnesia, Mnesia}, + {msg_index, MsgIndex}, + {other_ets, erlang:memory(ets) - Mnesia - MsgIndex}, + {binary, erlang:memory(binary)}, + {system, erlang:memory(system)}, + {atom, erlang:memory(atom)}, + {code, erlang:memory(code)}]. + +sum_proc_memory(Pids) -> + lists:foldl( + fun (Pid, Mem) -> Mem + element(2, process_info(Pid, memory)) end, + 0, Pids). + +pids(#amqqueue{pid = Pid, slave_pids = undefined}) -> + local_pids([Pid]); +pids(#amqqueue{pid = Pid, slave_pids = SPids}) -> + local_pids([Pid | SPids]). + +local_pids(Pids) -> [Pid || Pid <- Pids, node(Pid) =:= node()]. + +mnesia_memory() -> + lists:sum([bytes(mnesia:table_info(Tab, memory)) || + Tab <- mnesia:system_info(tables)]). + +ets_memory(Name) -> + lists:sum([bytes(ets:info(T, memory)) || T <- ets:all(), + N <- [ets:info(T, name)], + N =:= Name]). + +bytes(Words) -> Words * erlang:system_info(wordsize). |
