summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Klishin <michael@rabbitmq.com>2014-07-25 02:52:58 +0400
committerMichael Klishin <michael@rabbitmq.com>2014-07-25 02:52:58 +0400
commit22f5356c054912a4d59c27b06743f88b50655220 (patch)
treeaef6285f87b82b51114b2b8f718523c3dd017b08
parent3f93e3b1214605246a323f48bf1bfa4fc0de7429 (diff)
downloadrabbitmq-server-22f5356c054912a4d59c27b06743f88b50655220.tar.gz
Make vm_memory_monitor:parse_line_linux/1 parse lines w/o colons
Happens with some broken kernel modules.
-rw-r--r--src/vm_memory_monitor.erl33
1 files changed, 25 insertions, 8 deletions
diff --git a/src/vm_memory_monitor.erl b/src/vm_memory_monitor.erl
index 5fb1e472..3f4948f5 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,15 +309,29 @@ parse_line_mach(Line) ->
{list_to_atom(Name), list_to_integer(Value)}
end.
-%% A line looks like "FooBar: 123456 kB"
+extract_name_and_value_linux(Line) ->
+ {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,
+ {Name, Value1}.
+
+%% 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,
- {list_to_atom(Name), Value1}.
+ {Name, Val} = extract_name_and_value_linux(Line),
+ {list_to_atom(Name), Val}.
%% A line looks like "Memory size: 1024 Megabytes"
parse_line_sunos(Line) ->