Class: UnicornMetrics::RequestCounter

Inherits:
Counter
  • Object
show all
Defined in:
lib/unicorn_metrics/request_counter.rb

Overview

Counter defined to keep count of method types of http requests Requires the UnicornMetrics::Middleware

Constant Summary collapse

METHOD_COUNTERS =
[]

Instance Attribute Summary collapse

Attributes inherited from Counter

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Counter

#as_json, #reset, #type

Constructor Details

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

Returns a new instance of RequestCounter.

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_counter.rb', line 12

def initialize(name, method_name, path=nil)
  @path        = path
  @method_name = method_name.to_s.upcase
  METHOD_COUNTERS << 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_counter.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_counter.rb', line 5

def path
  @path
end

Class Method Details

.countersArray<UnicornMetrics::RequestCounter>

Returns:



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

def self.counters ; METHOD_COUNTERS ; end

.notify(meth_val, path) ⇒ 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_counter.rb', line 24

def self.notify(meth_val, path)
  counters.each { |c| c.increment if c.path_method_match?(meth_val, path) }
end

Instance Method Details

#path_method_match?(meth_val, path_val) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/unicorn_metrics/request_counter.rb', line 30

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