Class: UnicornMetrics::RequestTimer

Inherits:
Timer
  • Object
show all
Defined in:
lib/unicorn_metrics/request_timer.rb

Overview

Timer defined to keep track of total elapsed request time Requires the UnicornMetrics::Middleware

Constant Summary collapse

REQUEST_TIMERS =
[]

Constants inherited from Timer

Timer::EXPONENT

Instance Attribute Summary collapse

Attributes inherited from Timer

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Timer

#as_json, #reset, #sum, #tick, #type

Constructor Details

#initialize(name, method_name, path = nil) ⇒ RequestTimer

Returns a new instance of RequestTimer.

Parameters:

  • name (String)

    user-defined name

  • method_name (String)

    name of the HTTP method

  • path (Regex) (defaults to: nil)

    optional regex that is used to match to a specific URI



12
13
14
15
16
17
# File 'lib/unicorn_metrics/request_timer.rb', line 12

def initialize(name, method_name, path=nil)
  @path        = path
  @method_name = method_name.to_s
  REQUEST_TIMERS << self
  super(name)
end

Instance Attribute Details

#method_nameObject (readonly)

Returns the value of attribute method_name.



5
6
7
# File 'lib/unicorn_metrics/request_timer.rb', line 5

def method_name
  @method_name
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/unicorn_metrics/request_timer.rb', line 5

def path
  @path
end

Class Method Details

.notify(meth_val, path, elapsed_time) ⇒ Object

Parameters:

  • meth_val (String)

    is the HTTP method of the request

  • path (String)

    is the URI of the request



24
25
26
# File 'lib/unicorn_metrics/request_timer.rb', line 24

def self.notify(meth_val, path, elapsed_time)
  timers.each { |c| c.tick(elapsed_time) if c.path_method_match?(meth_val, path) }
end

.timersArray<UnicornMetrics::RequestTimer>

Returns:



20
# File 'lib/unicorn_metrics/request_timer.rb', line 20

def self.timers ; REQUEST_TIMERS ; end

Instance Method Details

#path_method_match?(meth_val, path_val) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/unicorn_metrics/request_timer.rb', line 31

def path_method_match?(meth_val, path_val)
  path_matches?(path_val) && method_matches?(meth_val)
end