Last Updated: October 12, 2018
·
375
· dpaluy

Process Information (Rails app)

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

Picture

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+/)
  @processes.map! { |line| line.strip.split(/\s+/, @proc_headers.size) }.
      reject! { |line| line.last.start_with?('ps -g') }
end

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

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

I would like to thank @romanbsd for this source.