Class: Leafy::Instrumented::BasicInstrumented

Inherits:
Object
  • Object
show all
Defined in:
lib/leafy/instrumented/basic_instrumented.rb

Direct Known Subclasses

CollectedInstrumented, Instrumented

Constant Summary collapse

NAME_PREFIX =
"responseCodes"

Instance Method Summary collapse

Constructor Details

#initialize(registry, name, meter_names_by_status_code = {}) ⇒ BasicInstrumented

creates the metrics. all none registered status codes are marked on the meter named ‘other’

Parameters:

  • the (Leafy::Metrics::Registry)

    registry on which register the metrics

  • name (String)

    basename of the metrics

  • map (Hash)

    of status code [Integer] to meter-name [String]. for each code there will be a meter.



13
14
15
16
17
18
19
# File 'lib/leafy/instrumented/basic_instrumented.rb', line 13

def initialize( registry, name, meter_names_by_status_code = {} )
  @meters_by_status_code = java.util.concurrent.ConcurrentHashMap.new
  meter_names_by_status_code.each do |k,v|
    @meters_by_status_code[ k ] = registry.register_meter( "#{name}.#{v}" )
  end
  @other = registry.register_meter( "#{name}.#{NAME_PREFIX}.other" )
end

Instance Method Details

#call(&block) ⇒ Object

basically wraps a rack middleware call



22
23
24
25
26
27
# File 'lib/leafy/instrumented/basic_instrumented.rb', line 22

def call( &block )
  raise "block needed" unless block_given?
  result = block.call
  mark_meter_for_status_code result[0]
  result
end

#mark_meter_for_status_code(status) ⇒ Object



29
30
31
32
# File 'lib/leafy/instrumented/basic_instrumented.rb', line 29

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