summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Sackman <matthew@lshift.net>2010-02-04 13:55:37 +0000
committerMatthew Sackman <matthew@lshift.net>2010-02-04 13:55:37 +0000
commit4291be65bed0055ee9d0bf2004c7e80114601829 (patch)
tree6af038c9ab36ea480958c6662ccb30e3bc286c1f
parent30aa0f6084dd0a78f9ef196bc76d5302b269b7bc (diff)
downloadrabbitmq-server-4291be65bed0055ee9d0bf2004c7e80114601829.tar.gz
Detect version of os_mon, and if we have version > 2.2.1 then we trust its output
-rw-r--r--src/rabbit_misc.erl34
-rw-r--r--src/vm_memory_monitor.erl27
2 files changed, 55 insertions, 6 deletions
diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl
index 172e27f4..2add5afb 100644
--- a/src/rabbit_misc.erl
+++ b/src/rabbit_misc.erl
@@ -56,6 +56,7 @@
-export([format_stderr/2]).
-export([start_applications/1, stop_applications/1]).
-export([unfold/2, ceil/1, queue_fold/3]).
+-export([version_compare/2, version_compare/3]).
-import(mnesia).
-import(lists).
@@ -499,3 +500,36 @@ queue_fold(Fun, Init, Q) ->
{empty, _Q} -> Init;
{{value, V}, Q1} -> queue_fold(Fun, Fun(V, Init), Q1)
end.
+
+version_compare(A, B, lte) ->
+ case version_compare(A, B) of
+ eq -> true;
+ lt -> true;
+ gt -> false
+ end;
+version_compare(A, B, gte) ->
+ case version_compare(A, B) of
+ eq -> true;
+ gt -> true;
+ lt -> false
+ end;
+version_compare(A, B, Result) ->
+ Result =:= version_compare(A, B).
+
+version_compare([], []) ->
+ eq;
+version_compare([], _ ) ->
+ lt; %% 2.3 < 2.3.1
+version_compare(_ , []) ->
+ gt; %% 2.3.1 > 2.3
+version_compare(A, B) ->
+ {AStr, ATl} = lists:splitwith(fun (X) -> X =/= $. end, A),
+ {BStr, BTl} = lists:splitwith(fun (X) -> X =/= $. end, B),
+ ANum = list_to_integer(AStr),
+ BNum = list_to_integer(BStr),
+ if ANum =:= BNum -> ATl1 = lists:dropwhile(fun (X) -> X =:= $. end, ATl),
+ BTl1 = lists:dropwhile(fun (X) -> X =:= $. end, BTl),
+ version_compare(ATl1, BTl1);
+ ANum < BNum -> lt;
+ ANum > BNum -> gt
+ end.
diff --git a/src/vm_memory_monitor.erl b/src/vm_memory_monitor.erl
index 02bd0499..0cdb4142 100644
--- a/src/vm_memory_monitor.erl
+++ b/src/vm_memory_monitor.erl
@@ -261,14 +261,29 @@ get_total_memory({unix,freebsd}) ->
PageCount * PageSize;
get_total_memory({win32,_OSname}) ->
- %% Due to the Erlang print format bug, on Windows boxes the memory size is
- %% broken. For example Windows 7 64 bit with 4Gigs of RAM we get negative
- %% memory size:
+ %% Due to the Erlang print format bug, on Windows boxes the memory
+ %% size is broken. For example Windows 7 64 bit with 4Gigs of RAM
+ %% we get negative memory size:
%% > os_mon_sysinfo:get_mem_info().
%% ["76 -1658880 1016913920 -1 -1021628416 2147352576 2134794240\n"]
- %% Due to this bug, we don't actually know anything. Even if the number is
- %% postive we can't be sure if it's correct.
- unknown;
+ %% Due to this bug, we don't actually know anything. Even if the
+ %% number is postive we can't be sure if it's correct. This only
+ %% affects us on os_mon versions prior to 2.2.1.
+ case application:get_key(os_mon, vsn) of
+ undefined ->
+ unknown;
+ {ok, Version} ->
+ case rabbit_misc:version_compare(Version, "2.2.1", lt) of
+ true -> %% os_mon is < 2.2.1, so we know nothing
+ unknown;
+ false ->
+ [Result|_] = os_mon_sysinfo:get_mem_info(),
+ {ok, [_MemLoad, TotPhys, _AvailPhys,
+ _TotPage, _AvailPage, _TotV, _AvailV], _RestStr} =
+ io_lib:fread("~d~d~d~d~d~d~d", Result),
+ TotPhys
+ end
+ end;
get_total_memory({unix, linux}) ->
File = read_proc_file("/proc/meminfo"),