Luca Scaljery wrote:
> Hi All
> 
> For the (RAILS) application I'm writing I need to know what the CPU
> usage is, any modules in Ruby that can do this (for a linux server)?
> 
> In my case, the server has to deal with many AJAX calls all the time. So
> when the CPU-usage gets too high, I would like to lower the
> AJAX-call-frequency dynamically.
> 
> Thnx a lot in advance
> LuCa

Are you looking for the overall system utilization? There are lots of
command-line tools you can use to log basic performance variables and
capture them in a pipe with Ruby, but in the long run, if you're really
interested in server performance monitoring, you probably should pick up
a whole performance logging package. RRDtool is probably the best, and
it has Ruby bindings. So you can let it collect the data and interrogate
its database periodically for the performance variables you need.

If you're willing to sacrifice portability away from Linux, I can give
you some quick-and-dirty code that will go directly into /proc and
snapshot this once every five minutes. But I think that's a bad idea --
I think you should keep your options open and get something that will
run on Linux, FreeBSD or Open Solaris.