Class: Leafy::Instrumented::Instrumented

Inherits:
BasicInstrumented show all
Defined in:
lib/leafy/instrumented/instrumented.rb

Constant Summary collapse

OK =
200
CREATED =
201
NO_CONTENT =
204
RESET_CONTENT =
205
BAD_REQUEST =
400
NOT_FOUND =
404
SERVER_ERROR =
500

Constants inherited from BasicInstrumented

BasicInstrumented::NAME_PREFIX

Instance Method Summary collapse

Constructor Details

#initialize(registry, name) ⇒ Instrumented

creates the some metrics for status code 200, 201, 204, 205, 400, 404 and 500. all none registered status codes are marked on the meter named ‘other’. further the request time get measured and the active request counter is maintained.

Parameters:

  • the (Leafy::Metrics::Registry)

    registry on which register the metrics

  • name (String)

    basename of the metrics



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/leafy/instrumented/instrumented.rb', line 19

def initialize( registry, name )
  super( registry, name,
         { OK => "#{NAME_PREFIX}.ok",
           CREATED => "#{NAME_PREFIX}.created",
           NO_CONTENT => "#{NAME_PREFIX}.noContent",
           RESET_CONTENT => "#{NAME_PREFIX}.resetContent",
           BAD_REQUEST => "#{NAME_PREFIX}.badRequest",
           NOT_FOUND => "#{NAME_PREFIX}.notFound",
           SERVER_ERROR => "#{NAME_PREFIX}.serverError" } )
  @active = registry.register_counter( "#{name}.active_requests" )
  @timer = registry.register_timer( "#{name}.requests" )
end

Instance Method Details

#call(&block) ⇒ Object

basically wraps a rack middleware call. mesures the request time and keeps an active request counter.



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/leafy/instrumented/instrumented.rb', line 34

def call( &block )
  raise "block needed" unless block_given?
  @active.inc

  @timer.time do

    super

  end
ensure
  @active.dec
end

#mark_meter_for_status_code(status) ⇒ Object



47
48
49
50
# File 'lib/leafy/instrumented/instrumented.rb', line 47

def mark_meter_for_status_code( status )
  metric = @meters_by_status_code[ status ] || @other
  metric.mark
end