mirror of
https://github.com/livebook-dev/livebook.git
synced 2024-12-27 01:42:11 +08:00
Show the correct amount of free memory available on the system (#1179)
* Show the correct amount of free memory available on the system Attempts to use the `available_memory` stat, otherwise tries to cobble it together using cached+buffered+free as per the erlang docs on `:memsup:get_system_memory_data` and only failing that flals back to `free_memory` * Use `Map.new` rather than `Enum.into` Co-authored-by: Jonatan Kłosko <jonatanklosko@gmail.com> * Update lib/livebook/system_resources.ex Co-authored-by: Jonatan Kłosko <jonatanklosko@gmail.com>
This commit is contained in:
parent
f5afac9497
commit
2a8c95c388
1 changed files with 11 additions and 1 deletions
|
@ -66,11 +66,21 @@ defmodule Livebook.SystemResources do
|
|||
|
||||
defp measure() do
|
||||
memory_data = :memsup.get_system_memory_data()
|
||||
memory = %{total: memory_data[:total_memory], free: memory_data[:free_memory]}
|
||||
free_memory = free_memory(Map.new(memory_data))
|
||||
memory = %{total: memory_data[:total_memory], free: free_memory}
|
||||
:ets.insert(@name, {:memory, memory})
|
||||
memory
|
||||
end
|
||||
|
||||
defp free_memory(%{available_memory: available}), do: available
|
||||
|
||||
defp free_memory(%{cached_memory: cached, buffered_memory: buffered, free_memory: free}) do
|
||||
cached + buffered + free
|
||||
end
|
||||
|
||||
defp free_memory(%{free_memory: free}), do: free
|
||||
defp free_memory(_), do: 0
|
||||
|
||||
defp schedule() do
|
||||
Process.send_after(self(), :measure, 15000)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue