Ruby on Rails Status Page

I like knowing what's going on on my servers, but I haven't had time to set up a real monitoring system. Usually when I want to check on my servers, I just remote in with SSH and fire up top and a couple other utilities. After I realized I tend to always check the same things again and again (CPU usage, RAM usage, free disk space), I decided to dump all those things into a page that my server would then serve up. This way I can check my server's health with from anywhere with an internet connection, and the time it took to set up was just a couple minutes.


  def status
    authorize! :status, User
    @monitors = []

    # Source:
    # Source:
    @monitors << {command: "top -b -n1 -o +%MEM -w 120 | head -n20", label: "top MEM"}
    @monitors << {command: "top -b -n1 -o +%CPU -w 120 | head -n20", label: "top CPU"}
    # Source:
    @monitors << {command: "free -m", label: "Free memory, in megabytes"}
    # Source:
    @monitors << {command: "df -h", label: "Disk usage, human-readable"}
    @monitors << {command: "passenger-status", label: "Phusion Passenger status"}
    @monitors << {command: "passenger-memory-stats", label: "passenger-memory-stats"}

    @monitors.each do |monitor|
      # Source:
      monitor[:result] = `#{monitor[:command]}`.gsub("\n", "<br/>")


<% @monitors.each do |monitor| %>
  <h1><%= monitor[:label] %></h1>
  <p>Command: <%= monitor[:command] %></p>
  <pre><%= monitor[:result].html_safe %></pre>
<% end %>


Photo by Antony Hollingworth