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 | 41c63bda8acf97fa9a6ee4dc8507a962ca913755 (patch) | |
| tree | d6e4814bd191f8854b8e2cfda6cb818f7fa3c908 /src | |
| parent | b5ecf2c371d3dd6c7308192d9bb353fbe37aed42 (diff) | |
| download | rabbitmq-server-git-41c63bda8acf97fa9a6ee4dc8507a962ca913755.tar.gz | |
Remove rabbit dependencies
Diffstat (limited to 'src')
| -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 436eaee46f..fb184d1ab2 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 |
