Class: Metrics::Integration::WEBrick
- Inherits:
-
WEBrick::HTTPServlet::AbstractServlet
- Object
- WEBrick::HTTPServlet::AbstractServlet
- Metrics::Integration::WEBrick
- Includes:
- Logging
- Defined in:
- lib/ruby-metrics/integration/webrick.rb
Class Method Summary collapse
Instance Method Summary collapse
- #do_GET(request, response) ⇒ Object
-
#initialize(server, agent) ⇒ WEBrick
constructor
A new instance of WEBrick.
Methods included from Logging
Constructor Details
#initialize(server, agent) ⇒ WEBrick
Returns a new instance of WEBrick.
35 36 37 |
# File 'lib/ruby-metrics/integration/webrick.rb', line 35 def initialize(server, agent) @agent = agent end |
Class Method Details
.start(options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ruby-metrics/integration/webrick.rb', line 17 def self.start( = {}) = {:Port => .delete(:port) || .delete(:Port) || 8001} agent = .delete(:agent) || Agent.new logger.debug "Creating Metrics daemon thread." @thread = Thread.new do begin server = ::WEBrick::HTTPServer.new() server.mount "/stats", self, agent server.start rescue Exception => e logger.error "Error in thread: %s: %s\n\t%s" % [e.class.to_s, e., e.backtrace.join("\n\t")] end end end |
Instance Method Details
#do_GET(request, response) ⇒ Object
39 40 41 42 43 |
# File 'lib/ruby-metrics/integration/webrick.rb', line 39 def do_GET(request, response) response.status = 200 response['Content-Type'] = 'application/json' response.body = @agent.to_json end |