Search code examples
rrserve

Query system load from R


Is there a way from R to be able to query a Linux OS and determine the number of active processes and/or CPU utilization? For example, the top command returns useful information to answer this, however system in R doesn't return a value that I can interact with, it just prints the STDOUT and moves on.

I'm working with Rserve behind a load balancer and I'd like to double check the load balancer is putting me on a server without excessive load.


Solution

  • Try system2("cat", "/proc/loadavg", stdout = TRUE) (see ?system2 for more info). (This is obviously just an example ... the key is adding stdout=TRUE to whatever command you are using.)