summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2012-09-18 18:08:32 +0100
committerSimon MacMullen <simon@rabbitmq.com>2012-09-18 18:08:32 +0100
commit0ea7e3149d81d1f52d744ca4f5ece15c375fa789 (patch)
tree8f3b18d0b617478f819814468f5918b54357ffb2 /src
parent2d024373c6791988ba707d2b80c91786819be00b (diff)
downloadrabbitmq-server-git-0ea7e3149d81d1f52d744ca4f5ece15c375fa789.tar.gz
rabbit_misc:memory/0.
Diffstat (limited to 'src')
-rw-r--r--src/rabbit.erl2
-rw-r--r--src/rabbit_misc.erl45
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).