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)
end
end
end
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>
Enjoy.
Tagged with