Class: Leafy::Instrumented::BasicInstrumented
- Inherits:
-
Object
- Object
- Leafy::Instrumented::BasicInstrumented
- Defined in:
- lib/leafy/instrumented/basic_instrumented.rb
Direct Known Subclasses
Constant Summary collapse
- NAME_PREFIX =
"responseCodes"
Instance Method Summary collapse
- #call(&block) ⇒ Object
-
#initialize(registry, name, meter_names_by_status_code = {}) ⇒ BasicInstrumented
constructor
A new instance of BasicInstrumented.
- #mark_meter_for_status_code(status) ⇒ Object
Constructor Details
#initialize(registry, name, meter_names_by_status_code = {}) ⇒ BasicInstrumented
Returns a new instance of BasicInstrumented.
7 8 9 10 11 12 13 14 15 |
# File 'lib/leafy/instrumented/basic_instrumented.rb', line 7 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" ) @active = registry.register_counter( "#{name}.active_requests" ) @timer = registry.register_timer( "#{name}.requests" ) end |
Instance Method Details
#call(&block) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/leafy/instrumented/basic_instrumented.rb', line 17 def call( &block ) raise "block needed" unless block_given? @active.inc @timer.time do result = block.call mark_meter_for_status_code result[0] result end ensure @active.dec end |
#mark_meter_for_status_code(status) ⇒ Object
32 33 34 35 |
# File 'lib/leafy/instrumented/basic_instrumented.rb', line 32 def mark_meter_for_status_code( status ) metric = @meters_by_status_code[ status ] || @other metric.mark end |