Unable to read from procfs?

I have a project where I am additionally trying to get some system info (system memory usage, load averages, etc), but since Elixir or Erlang doesn’t seem to have something to the effect of what psutil can do for Python, I figured I’d just grab info the way that the OS expects you to. For my issue here, trying to simply read /proc/loadavg. If I simply do cat /proc/loadavg then I get the info, likewise I can get the info with Python using psutil. I figured I could simply do a File.read/1 but that doesn’t appear to work. This is what I get:

iex> File.read!("/proc/loadavg")
{:ok, ""}

Not sure why Elixir can’t read from procfs. Feels kind of cheesy calling cat for this.

I can, on my linux box:

Erlang/OTP 21 [erts-10.2.4] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1]

Interactive Elixir (1.10.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> File.read!("/proc/loadavg")
"0.00 0.00 0.00 2/161 7931\n"
1 Like

Have you tried os_mon?


Well that’s weird. All of a sudden today it decided to do it. I was doing it on an Ubuntu 18.04 VM

Wow I had a hard time finding that. This is what I needed. Thank you!