summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2014-07-25 11:38:10 +0100
committerSimon MacMullen <simon@rabbitmq.com>2014-07-25 11:38:10 +0100
commit78e32ab7f920ed0cc5acf15fea30a7aff446bdd4 (patch)
tree5b903f6903772f8c0559677a81cb33e03e74613b
parent9da4e18e7c51d2df1b229396b8d702851e80910e (diff)
parente9bcae802cfa276d5d8ce6cc2b56fe5816e57493 (diff)
downloadrabbitmq-server-78e32ab7f920ed0cc5acf15fea30a7aff446bdd4.tar.gz
Merge bug26290
-rw-r--r--src/rabbit_tests.erl1
-rw-r--r--src/vm_memory_monitor.erl27
-rw-r--r--src/vm_memory_monitor_tests.erl35
3 files changed, 56 insertions, 7 deletions
diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl
index ab95196d..da6938bd 100644
--- a/src/rabbit_tests.erl
+++ b/src/rabbit_tests.erl
@@ -76,6 +76,7 @@ all_tests() ->
passed
end),
passed = test_configurable_server_properties(),
+ passed = vm_memory_monitor_tests:all_tests(),
passed.
diff --git a/src/vm_memory_monitor.erl b/src/vm_memory_monitor.erl
index 5fb1e472..52d09e20 100644
--- a/src/vm_memory_monitor.erl
+++ b/src/vm_memory_monitor.erl
@@ -37,6 +37,9 @@
get_vm_memory_high_watermark/0, set_vm_memory_high_watermark/1,
get_memory_limit/0]).
+%% for tests
+-export([parse_line_linux/1]).
+
-define(SERVER, ?MODULE).
-define(DEFAULT_MEMORY_CHECK_INTERVAL, 1000).
@@ -306,14 +309,24 @@ parse_line_mach(Line) ->
{list_to_atom(Name), list_to_integer(Value)}
end.
-%% A line looks like "FooBar: 123456 kB"
+%% A line looks like "MemTotal: 502968 kB"
+%% or (with broken OS/modules) "Readahead 123456 kB"
parse_line_linux(Line) ->
- [Name, RHS | _Rest] = string:tokens(Line, ":"),
- [Value | UnitsRest] = string:tokens(RHS, " "),
- Value1 = case UnitsRest of
- [] -> list_to_integer(Value); %% no units
- ["kB"] -> list_to_integer(Value) * 1024
- end,
+ {Name, Value, UnitRest} =
+ case string:tokens(Line, ":") of
+ %% no colon in the line
+ [S] ->
+ [K, RHS] = re:split(S, "\s", [{parts, 2}, {return, list}]),
+ [V | Unit] = string:tokens(RHS, " "),
+ {K, V, Unit};
+ [K, RHS | _Rest] ->
+ [V | Unit] = string:tokens(RHS, " "),
+ {K, V, Unit}
+ end,
+ Value1 = case UnitRest of
+ [] -> list_to_integer(Value); %% no units
+ ["kB"] -> list_to_integer(Value) * 1024
+ end,
{list_to_atom(Name), Value1}.
%% A line looks like "Memory size: 1024 Megabytes"
diff --git a/src/vm_memory_monitor_tests.erl b/src/vm_memory_monitor_tests.erl
new file mode 100644
index 00000000..1f7cea33
--- /dev/null
+++ b/src/vm_memory_monitor_tests.erl
@@ -0,0 +1,35 @@
+%% The contents of this file are subject to the Mozilla Public License
+%% Version 1.1 (the "License"); you may not use this file except in
+%% compliance with the License. You may obtain a copy of the License at
+%% http://www.mozilla.org/MPL/
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+%% License for the specific language governing rights and limitations
+%% under the License.
+%%
+%% The Original Code is RabbitMQ.
+%%
+%% The Initial Developer of the Original Code is GoPivotal, Inc.
+%% Copyright (c) 2007-2014 GoPivotal, Inc. All rights reserved.
+%%
+
+-module(vm_memory_monitor_tests).
+
+-export([all_tests/0]).
+
+%% ---------------------------------------------------------------------------
+%% Tests
+%% ---------------------------------------------------------------------------
+
+all_tests() ->
+ lists:foreach(fun ({S, {K, V}}) ->
+ {K, V} = vm_memory_monitor:parse_line_linux(S)
+ end,
+ [{"MemTotal: 0 kB", {'MemTotal', 0}},
+ {"MemTotal: 502968 kB ", {'MemTotal', 515039232}},
+ {"MemFree: 178232 kB", {'MemFree', 182509568}},
+ {"MemTotal: 50296888", {'MemTotal', 50296888}},
+ {"MemTotal 502968 kB", {'MemTotal', 515039232}},
+ {"MemTotal 50296866 ", {'MemTotal', 50296866}}]),
+ passed.