summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Fedotov <dfedotov@pivotal.io>2017-06-13 14:59:07 +0100
committerDaniil Fedotov <dfedotov@pivotal.io>2017-06-13 14:59:07 +0100
commit6a84ef415d5b493f5ee4008883e5cd34cdc923af (patch)
tree8a33f22e99a0ab572ec3934986fbf9b734240706
parenta83efdf60c4d90f1b2f37beecac1af0c05861c5b (diff)
downloadrabbitmq-server-git-6a84ef415d5b493f5ee4008883e5cd34cdc923af.tar.gz
Current process system memory functions for various OSes.
According to AIX, SunOS and BSD docs, ps command can have rss format, so get_ps_memory should work. We already requiring tasklist for wait command, so we can use it here.
-rw-r--r--src/vm_memory_monitor.erl21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/vm_memory_monitor.erl b/src/vm_memory_monitor.erl
index a3a36e9fbd..0bbca55eed 100644
--- a/src/vm_memory_monitor.erl
+++ b/src/vm_memory_monitor.erl
@@ -384,19 +384,30 @@ get_system_process_resident_memory({unix, linux}) ->
get_ps_memory();
get_system_process_resident_memory({unix,freebsd}) ->
- {error, not_implemented_for_os};
+ get_ps_memory();
get_system_process_resident_memory({unix,openbsd}) ->
- {error, not_implemented_for_os};
+ get_ps_memory();
get_system_process_resident_memory({win32,_OSname}) ->
- {error, not_implemented_for_os};
+ OsPid = os:getpid(),
+ Cmd = " tasklist /fi \"pid eq " ++ OsPid ++ "\" /fo LIST 2>&1 ",
+ CmdOutput = os:cmd(Cmd),
+ %% Memory usage is displayed in kilobytes
+ %% with comma-separated thousands
+ case re:run(CmdOutput, "Mem Usage:\\s+([0-9,]+)\\s+K", [{capture, all_but_first, list}]) of
+ {match, [Match]} ->
+ NoCommas = [ N || N <- Match, N =/= $, ],
+ {ok, list_to_integer(NoCommas) * 1024};
+ _ ->
+ {error, {unexpected_output_from_command, Cmd, CmdOutput}}
+ end;
get_system_process_resident_memory({unix, sunos}) ->
- {error, not_implemented_for_os};
+ get_ps_memory();
get_system_process_resident_memory({unix, aix}) ->
- {error, not_implemented_for_os};
+ get_ps_memory();
get_system_process_resident_memory(_OsType) ->
{error, not_implemented_for_os}.