Class: Yabeda::Latency::Collector

Inherits:
Object
  • Object
show all
Defined in:
lib/yabeda/latency/collector.rb

Overview

Collector is a Rack middleware that provides meaures the latency of an HTTP request based on the “X-Request-Start” header.

By default metrics all have the prefix “http_server”. Set ‘:metrics_prefix` to something else if you like.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, metrics_prefix: :http_server, debug: false) ⇒ Collector

Returns a new instance of Collector.



17
18
19
20
21
22
23
# File 'lib/yabeda/latency/collector.rb', line 17

def initialize(app, metrics_prefix: :http_server, debug: false)
  @app = app
  @metrics_prefix = metrics_prefix
  @debug = debug

  init_request_metrics
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



15
16
17
# File 'lib/yabeda/latency/collector.rb', line 15

def app
  @app
end

#registryObject (readonly)

Returns the value of attribute registry.



15
16
17
# File 'lib/yabeda/latency/collector.rb', line 15

def registry
  @registry
end

Instance Method Details

#call(env) ⇒ Object

:nodoc:



25
26
27
28
29
30
31
# File 'lib/yabeda/latency/collector.rb', line 25

def call(env) # :nodoc:
  return @app.call(env) if env['rack.warming_up']

  now = Time.now
  observe(env, now)
  @app.call(env)
end