Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect freemem report in docker containers #377

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 5 additions & 19 deletions src/tsung_controller/ts_os_mon_erlang.erl
Original file line number Diff line number Diff line change
Expand Up @@ -262,25 +262,11 @@ get_os_data(DataName) -> get_os_data(DataName,os:type()).
%% Use the result of the free commands on Linux and os_mon on all
%% other platforms
get_os_data(freemem, {unix, linux}) ->
case file:open("/proc/meminfo",[raw,read]) of
{ok, FD} ->
file:read_line(FD), % skip MemTotal
{ok, Data} = file:read_line(FD),
["MemFree:",RawFree,_] = string:tokens(Data," \n"),
case file:read_line(FD) of
{ok, "MemAvailable:" ++Tail} ->
[Avail,_] = string:tokens(Tail," \n"),
file:close(FD),
list_to_integer(Avail)/1024;
{ok, NextLine} ->
["Buffers:",Buf,_] = string:tokens(NextLine," \n"),
{ok, LastLine} = file:read_line(FD),
["Cached:",Cached,_] = string:tokens(LastLine," \n"),
file:close(FD),
(list_to_integer(RawFree)+list_to_integer(Buf) + list_to_integer(Cached)) / 1024
end;
_ ->
0
case os:cmd("awk '/^MemFree|^Cached|^Buffers/ {freemem+=$2} END {print freemem}' /proc/meminfo") of
"" -> 0;
Data ->
RealFreeMem = string:strip(Data, right, $\n),
list_to_integer(RealFreeMem) / 1024
end;
get_os_data(freemem, {unix, sunos}) ->
Result = os:cmd("vmstat 1 2 | tail -1"),
Expand Down