diff options
author | Emile Joubert <emile@rabbitmq.com> | 2012-03-26 11:18:31 +0100 |
---|---|---|
committer | Emile Joubert <emile@rabbitmq.com> | 2012-03-26 11:18:31 +0100 |
commit | 1b3057567882a548743ea5dc9084c243ed4edb64 (patch) | |
tree | d6e4814bd191f8854b8e2cfda6cb818f7fa3c908 | |
parent | 53e526ce30e49f06a6b7b9965ef605b0e57f59af (diff) | |
download | rabbitmq-server-1b3057567882a548743ea5dc9084c243ed4edb64.tar.gz |
Remove rabbit dependencies
-rw-r--r-- | src/vm_memory_monitor.erl | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/vm_memory_monitor.erl b/src/vm_memory_monitor.erl index 436eaee4..fb184d1a 100644 --- a/src/vm_memory_monitor.erl +++ b/src/vm_memory_monitor.erl @@ -223,13 +223,19 @@ get_mem_limit(MemFraction, TotalMemory) -> %%---------------------------------------------------------------------------- %% Internal Helpers %%---------------------------------------------------------------------------- +cmd(Command) -> + Exec = hd(string:tokens(Command, " ")), + case os:find_executable(Exec) of + false -> throw({command_not_found, Exec}); + _ -> os:cmd(Command) + end. %% get_total_memory(OS) -> Total %% Windows and Freebsd code based on: memsup:get_memory_usage/1 %% Original code was part of OTP and released under "Erlang Public License". get_total_memory({unix,darwin}) -> - File = rabbit_misc:os_cmd("/usr/bin/vm_stat"), + File = cmd("/usr/bin/vm_stat"), Lines = string:tokens(File, "\n"), Dict = dict:from_list(lists:map(fun parse_line_mach/1, Lines)), [PageSize, Inactive, Active, Free, Wired] = @@ -278,13 +284,13 @@ get_total_memory({unix, linux}) -> dict:fetch('MemTotal', Dict); get_total_memory({unix, sunos}) -> - File = rabbit_misc:os_cmd("/usr/sbin/prtconf"), + File = cmd("/usr/sbin/prtconf"), Lines = string:tokens(File, "\n"), Dict = dict:from_list(lists:map(fun parse_line_sunos/1, Lines)), dict:fetch('Memory size', Dict); get_total_memory({unix, aix}) -> - File = rabbit_misc:os_cmd("/usr/bin/vmstat -v"), + File = cmd("/usr/bin/vmstat -v"), Lines = string:tokens(File, "\n"), Dict = dict:from_list(lists:map(fun parse_line_aix/1, Lines)), dict:fetch('memory pages', Dict) * 4096; @@ -346,7 +352,7 @@ parse_line_aix(Line) -> end}. sysctl(Def) -> - list_to_integer(rabbit_misc:os_cmd("/sbin/sysctl -n " ++ Def) -- "\n"). + list_to_integer(cmd("/sbin/sysctl -n " ++ Def) -- "\n"). %% file:read_file does not work on files in /proc as it seems to get %% the size of the file first and then read that many bytes. But files |