2017-03-23 10 views
1

私はエリクサーアプリからサードパーティのスクリプトを使用しています。私の仕事用アプリでどれくらいのメモリが利用可能であるかをどのように知ることができますか?私は私が見つけた最も明白な(しかし、少し面倒な)方法は、コマンドラインからvmstatを呼び出し、それが結果解析することですエリクサーでサーバー上の使用可能なメモリの量を知る方法はありますか?

+0

http://stackoverflow.com/questions/42677595/how-can-i-check-memory-usage-in-elixir –

+0

これは複製です:( – asiniy

+1

[Elixirのメモリ使用量を確認するにはどうすればよいですか?] (http://stackoverflow.com/questions/42677595/how-can-i-check-memory-usage-in-elixir) – asiniy

答えて

2

にErlangのVMで使用可能なメモリを必要とするが、全体のコンピュータメモリはありません。

System.cmd("vmstat", ["-s", "-SM"]) 
    |> elem(0) 
    |> String.trim() 
    |> String.split() 
    |> List.first() 
    |> String.to_integer() 
    |> Kernel.*(1_000_000) # convert megabytes to bytes 

vmstat はUbuntuの上で動作し、そのような出力返すコマンドです:Ubuntuで

  3986 M total memory 
     3736 M used memory 
     3048 M active memory 
      525 M inactive memory 
      249 M free memory 
      117 M buffer memory 
      930 M swap cache 
      0 M total swap 
      0 M used swap 
      0 M free swap 
     1431707 non-nice user cpu ticks 
     56301 nice user cpu ticks 
     232979 system cpu ticks 
     3267984 idle cpu ticks 
     84908 IO-wait cpu ticks 
      0 IRQ cpu ticks 
     15766 softirq cpu ticks 
      0 stolen cpu ticks 
     4179948 pages paged in 
     6422812 pages paged out 
      0 pages swapped in 
      0 pages swapped out 
    35819291 interrupts 
    145676723 CPU context switches 
    1490259647 boot time 
     67936 forks 

作品は、すべてのLinux上で動作するはずですが

関連する問題