Class: EventMachine::Middleware::Metrics

Inherits:
Object
  • Object
show all
Defined in:
lib/em-http-metrics.rb

Instance Method Summary collapse

Constructor Details

#initialize(metrics) ⇒ Metrics

Returns a new instance of Metrics.



14
15
16
17
# File 'lib/em-http-metrics.rb', line 14

def initialize(metrics)
  @metrics = metrics
  @conn = {}
end

Instance Method Details

#request(client, head, body) ⇒ Object



19
20
21
22
# File 'lib/em-http-metrics.rb', line 19

def request(client, head, body)
  @conn[client.hash] = Time.new
  [head, body]
end

#response(resp) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/em-http-metrics.rb', line 24

def response(resp)
  timestamp = Time.new
  t = timestamp - @conn[resp.hash]
  @conn.delete resp.hash
  @metrics << {
    :time      => t,
    :timestamp => timestamp,
    :status    => resp.response_header.status,
    :uri       => resp.req.uri.to_s
  }
  resp
end