Skip to content

Commit eb7e6af

Browse files
committed
Use new config parameter total_memory_available_override_value to set total memory
rabbitmq-server#1224 [#145450413]
1 parent ced8290 commit eb7e6af

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

docs/rabbitmq.config.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@
246246
%%
247247
%% {memory_monitor_interval, 2500},
248248

249+
%% The total memory available can be calculated from the OS resources
250+
%% - default option - or provided as a configuration parameter:
251+
%% {total_memory_available_override_value, "5000MB"}
252+
249253
%% Set disk free limit (in bytes). Once free disk space reaches this
250254
%% lower bound, a disk alarm will be set - see the documentation
251255
%% listed above for more details.

src/vm_memory_monitor.erl

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,20 @@
7979
%%----------------------------------------------------------------------------
8080

8181
get_total_memory() ->
82-
try
83-
get_total_memory(os:type())
84-
catch _:Error ->
85-
rabbit_log:warning(
86-
"Failed to get total system memory: ~n~p~n~p~n",
87-
[Error, erlang:get_stacktrace()]),
88-
unknown
82+
case application:get_env(rabbit, total_memory_available_override_value) of
83+
{ok, Value} ->
84+
case rabbit_resource_monitor_misc:parse_information_unit(Value) of
85+
{ok, ParsedTotal} ->
86+
ParsedTotal;
87+
{error, parse_error} ->
88+
rabbit_log:warning(
89+
"The override value for the total memmory available is "
90+
"not a valid value: ~p, getting total from the system.~n",
91+
[Value]),
92+
get_total_memory_from_os()
93+
end;
94+
undefined ->
95+
get_total_memory_from_os()
8996
end.
9097

9198
get_vm_limit() -> get_vm_limit(os:type()).
@@ -164,6 +171,15 @@ code_change(_OldVsn, State, _Extra) ->
164171
%%----------------------------------------------------------------------------
165172
%% Server Internals
166173
%%----------------------------------------------------------------------------
174+
get_total_memory_from_os() ->
175+
try
176+
get_total_memory(os:type())
177+
catch _:Error ->
178+
rabbit_log:warning(
179+
"Failed to get total system memory: ~n~p~n~p~n",
180+
[Error, erlang:get_stacktrace()]),
181+
unknown
182+
end.
167183

168184
set_mem_limits(State, MemLimit) ->
169185
case erlang:system_info(wordsize) of

0 commit comments

Comments
 (0)