nwom5q
Last Updated: February 25, 2016
·
225
· dpaluy
3129de6b479cc965513311f1ddcc268a

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.

Say Thanks
Respond
Awesome Job

20838750 ca12 11e7 8395 3d07316c018d
Overijssel,Amsterdam, Arnhem
·
Overijssel, Amsterdam, Arnhem
·
Full Time