Paluy on Miscellaneous

Of course I'm an optimist - I don't see much point in being anything else. - Winston Churchill

Process Information

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/admin_controller.rb:

1
2
3
4
5
6
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<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.

Comments