summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTony Garnock-Jones <tonyg@lshift.net>2008-11-25 16:20:44 +0000
committerTony Garnock-Jones <tonyg@lshift.net>2008-11-25 16:20:44 +0000
commitc09c7663cc3240374388e7836340266091a27c10 (patch)
treec22b88797dc45e1b0b05b7697aef5d04684be4d6
parentfe8711c9e6aa9862fd5716c020b4356497829d52 (diff)
parentd53b45af39bddb0f1f7c55dc0e39b1e15262552b (diff)
downloadrabbitmq-server-c09c7663cc3240374388e7836340266091a27c10.tar.gz
merge bug19790 into default
-rw-r--r--src/rabbit_alarm.erl19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/rabbit_alarm.erl b/src/rabbit_alarm.erl
index d9c1c450..c2d6aaff 100644
--- a/src/rabbit_alarm.erl
+++ b/src/rabbit_alarm.erl
@@ -77,7 +77,9 @@ register(Pid, HighMemMFA) ->
%%----------------------------------------------------------------------------
init([]) ->
- {ok, #alarms{alertees = dict:new()}}.
+ HWM = system_memory_high_watermark(),
+ {ok, #alarms{alertees = dict:new(),
+ system_memory_high_watermark = HWM}}.
handle_call({register, Pid, HighMemMFA},
State = #alarms{alertees = Alertess}) ->
@@ -118,7 +120,20 @@ code_change(_OldVsn, State, _Extra) ->
{ok, State}.
%%----------------------------------------------------------------------------
-
+
+system_memory_high_watermark() ->
+ %% When we register our alarm_handler, the
+ %% system_memory_high_watermark alarm may already have gone
+ %% off. How do we find out about that? Calling
+ %% alarm_handler:get_alarms() would deadlock. So instead we ask
+ %% memsup. Unfortunately that doesn't expose a suitable API, so we
+ %% have to reach quite deeply into its internals.
+ {dictionary, D} = process_info(whereis(memsup), dictionary),
+ case lists:keysearch(system_memory_high_watermark, 1, D) of
+ {value, {_, set}} -> true;
+ _Other -> false
+ end.
+
alert(Alert, Alertees) ->
dict:fold(fun (Pid, {M, F, A}, Acc) ->
ok = erlang:apply(M, F, A ++ [Pid, Alert]),