Last Updated: October 12, 2018
· dpaluy

Process Information (Rails app)

I found it very useful to see my application process info on an admin page, as following:


You can do it inside your Rails app.

Inside your controller/admincontroller.rb_:

def index
  @processes = `ps -g #{Process.getsid($$)} -o pid,wchan,%cpu,%mem,rss,vsz,command`.strip.split("\n")
  @proc_headers = @processes.shift.split(/\s+/)! { |line| line.strip.split(/\s+/, @proc_headers.size) }.
      reject! { |line| line.last.start_with?('ps -g') }

and add the following to your view/admin/index.html.erb

    <% @proc_headers.each do |th| %>
      <th><%= th %></th>
    <% end %>
    <% @processes.each do |line| %>
      <% line.each do |td| %>
        <td><%= td %></td>
      <% end %>
    <% end %>

I would like to thank @romanbsd for this source.