Class: PDTP::Server::StatusHandler
- Inherits:
-
Mongrel::HttpHandler
- Object
- Mongrel::HttpHandler
- PDTP::Server::StatusHandler
- Defined in:
- lib/pdtp/server/status_handler.rb
Overview
set up the mongrel server for serving the stats page
Instance Method Summary collapse
-
#generate_html_stats ⇒ Object
builds an html page with information about the server’s internal workings.
-
#initialize(dispatcher) ⇒ StatusHandler
constructor
A new instance of StatusHandler.
-
#process(request, response) ⇒ Object
process an incoming request to the admin page.
Constructor Details
#initialize(dispatcher) ⇒ StatusHandler
Returns a new instance of StatusHandler.
33 34 35 |
# File 'lib/pdtp/server/status_handler.rb', line 33 def initialize(dispatcher) @dispatcher = dispatcher end |
Instance Method Details
#generate_html_stats ⇒ Object
builds an html page with information about the server’s internal workings
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/pdtp/server/status_handler.rb', line 49 def generate_html_stats s = ERB.new <<EOF <html><head><title>DistribuStream Status</title></head> <body> <h1>DistribuStream Status</h1> Time=<%= Time.now %><br> Connected Clients=<%= @dispatcher.connections.size %> <center><table border="1"> <tr><th>Client</th><th>Transfers</th><th>Files</th></tr> <% @dispatcher.connections.each do |c| %> <tr><td> <% if c.file_service? %> <b>File Service</b> <% else %> <%= @dispatcher.connection_name(c) %> <% end %> <% host, port = c.get_peer_info %> <br><%= host %>:<%= port %> </td> <td> <% @dispatcher.client_info(c).transfers.each do |key,t| if c==t.giver type="UP: " peer=t.taker else type="DOWN: " peer=t.giver end %> <%= type %> id=<%= t.transfer_id %><br> <% end %> </td> <td> <% @dispatcher.client_info(c).chunk_info.get_file_stats.each do |fs| %> <%= fs.url %> size=<%= fs.file_chunks %> req=<%= fs.chunks_requested %> prov=<%= fs.chunks_provided %> transf=<%= fs.chunks_transferring %><br> <% end %> </td></tr> <% end %> </table> </body></html> EOF s.result binding end |
#process(request, response) ⇒ Object
process an incoming request to the admin page
38 39 40 41 42 43 44 45 46 |
# File 'lib/pdtp/server/status_handler.rb', line 38 def process(request, response) response.start(200) do |head, out| out.write begin generate_html_stats rescue Exception => e "Exception: #{e}\n#{e.backtrace.join("\n")}" end end end |