Class: Simple::Metrics::RackMetrics

Inherits:
Object
  • Object
show all
Extended by:
Meter
Defined in:
lib/simple/metrics/rack_metrics.rb

Constant Summary

Constants included from Simple::Metrics

DEFAULT_DURATION_UNIT, DEFAULT_RATE_UNIT, DEFAULT_TIMING_UNIT, VERSION

Instance Method Summary collapse

Methods included from Meter

define_meter

Methods included from Simple::Metrics

#metrics_registry, #new_metric_name, #sanitize_classname

Methods included from Timer

#timer

Constructor Details

#initialize(app, application_name) ⇒ RackMetrics

Rack middleware for capturing response codes

Creates a series of response meters that will be marked based on the response code that is returned by rack.

Parameters:

  • app (Object)

    Rack application

  • application_name (String)

    The name of the application



12
13
14
15
16
17
18
19
# File 'lib/simple/metrics/rack_metrics.rb', line 12

def initialize(app, application_name)
  @app = app

  self.class.define_meter '2xx-responses', application_name
  self.class.define_meter '3xx-responses', application_name
  self.class.define_meter '4xx-responses', application_name
  self.class.define_meter '5xx-responses', application_name
end

Instance Method Details

#call(env) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/simple/metrics/rack_metrics.rb', line 21

def call(env)
  begin
    status, headers, body = @app.call(env)
  ensure
    status_code = (status ||= 500).to_s[0]
    status_method = "#{status_code}xx-responses".to_sym
    self.send(status_method).mark
  end
end