Class: UnicornMetrics::ResponseCounter

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

Overview

Counter defined to keep count of status codes of http responses Requires the UnicornMetrics::Middleware

Constant Summary collapse

STATUS_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, status_code, path = nil) ⇒ ResponseCounter

Returns a new instance of ResponseCounter.

Parameters:

  • name (String)

    user-defined name

  • status_code (Regex)

    the HTTP status code (e.g., ‘/[2]d2/`)

  • 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/response_counter.rb', line 12

def initialize(name, status_code, path=nil)
  @path        = path
  @status_code = status_code
  STATUS_COUNTERS << self
  super(name)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



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

def status_code
  @status_code
end

Class Method Details

.countersArray<UnicornMetrics::ResponseCounter>



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

def self.counters ; STATUS_COUNTERS ; end

.notify(status, path) ⇒ Object

Parameters:

  • status (String)

    is the HTTP status code of the request

  • path (String)

    is the URI of the request



25
26
27
# File 'lib/unicorn_metrics/response_counter.rb', line 25

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

Instance Method Details

#path_status_match?(status, path) ⇒ Boolean

Returns:

  • (Boolean)


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

def path_status_match?(status,path)
  status_matches?(status) && path_matches?(path)
end