Jim Neath

Manchester based Ruby on Rails & Facebook App Developer

If you’ve ever wanted to know how many active or idle Passenger processes your server has and display them inside your app, you can use the following helper:

def passenger_stats
  @passenger_stats ||= begin
    `passenger-status`.split("\n")[1..4].inject({}) do |memo, line| 
      memo.merge(line[/^\w+/].to_sym => line[/\d+$/].to_i)

Calling passenger_stats will return a hash resembling the following:

{ :inactive => 1, :count => 4, :max => 15, :active => 3 }

Which you could then display in your views, thus:

<h3>Passenger Stats</h3>
<p><strong>Total:</strong> <%= passenger_stats[:total] %></p>
<p><strong>Maximum:</strong> <%= passenger_stats[:max] %></p>
<p><strong>Active:</strong> <%= passenger_stats[:active] %></p>
<p><strong>Inactive:</strong> <%= passenger_stats[:inactive] %></p>


blog comments powered by Disqus

I am available for freelance work! Click here to email me.

Jim Neath is a Freelance Ruby on Rails & Facebook app developer from Manchester, UK, currently working for Engine Yard.