class Mongrel::StatusHandler

The :stats_filter is basically any configured stats filter that you've added to this same URI. This lets the status handler print out statistics on how Mongrel is doing.

Public Class Methods

new(ops={}) click to toggle source
# File lib/mongrel/handlers.rb, line 371
def initialize(ops={})
  @stats = ops[:stats_filter]
end

Public Instance Methods

describe_listener() click to toggle source
# File lib/mongrel/handlers.rb, line 385
def describe_listener
  results = ""
  results << "<h1>Listener #{listener.host}:#{listener.port}</h1>"
  results << table("settings", [
                   ["host",listener.host],
                   ["port",listener.port],
                   ["throttle",listener.throttle],
                   ["timeout",listener.timeout],
                   ["workers max",listener.num_processors],
  ])

  if @stats
    results << "<h2>Statistics</h2><p>N means the number of samples, pay attention to MEAN, SD, MIN and MAX."
    results << "<pre>#{@stats.dump}</pre>"
  end

  results << "<h2>Registered Handlers</h2>"
  handler_map = listener.classifier.handler_map
  results << table("handlers", handler_map.map {|uri,handlers| 
    [uri, 
        "<pre>" + 
        handlers.map {|h| h.class.to_s }.join("\n") + 
        "</pre>"
    ]
  })

  results
end
process(request, response) click to toggle source
# File lib/mongrel/handlers.rb, line 414
    def process(request, response)
      response.start do |head,out|
        out.write <<-END
        <html><body><title>Mongrel Server Status</title>
        #{describe_listener}
        </body></html>
        END
      end
    end
table(title, rows) click to toggle source
# File lib/mongrel/handlers.rb, line 375
def table(title, rows)
  results = "<table border=\"1\"><tr><th colspan=\"#{rows[0].length}\">#{title}</th></tr>"
  rows.each do |cols|
    results << "<tr>"
    cols.each {|col| results << "<td>#{col}</td>" }
    results << "</tr>"
  end
  results + "</table>"
end