class Metrics::Instrumenter
Public: Responsible for sampling a measurement of something.
metric - The name of the metric to measure (e.g. rack.request.time) options - Hash of options (default: {}):
unit: Unit of measurement [ms, MB, GB, ...] (optional) type: Method type of the measurement [measure, sample, count] (optional, default: measure)
Returns a new Metrics::Instrumenter
.
Constants
- TIME_UNITS
Attributes
block[R]
metric[R]
options[R]
Public Class Methods
instrument(*args, &block)
click to toggle source
# File lib/metrics/instrumenter.rb, line 16 def self.instrument(*args, &block) instrument = new(*args, &block) instrument.value instrument end
new(metric, *args, &block)
click to toggle source
# File lib/metrics/instrumenter.rb, line 22 def initialize(metric, *args, &block) @metric = metric @options = extract_options!(args) @block = block @value = args.first if args.length > 0 end
Public Instance Methods
result()
click to toggle source
# File lib/metrics/instrumenter.rb, line 53 def result return nil unless block return @result if defined?(@result) @result = block.call end
source()
click to toggle source
# File lib/metrics/instrumenter.rb, line 45 def source options[:source] end
type()
click to toggle source
# File lib/metrics/instrumenter.rb, line 41 def type options[:type] || 'measure' end
units()
click to toggle source
# File lib/metrics/instrumenter.rb, line 37 def units timing? ? TIME_UNITS : options[:units] end
value()
click to toggle source
Public: Runs the instrumenter.
Returns the run time if a block was supplied. Returns the value if the
# File lib/metrics/instrumenter.rb, line 33 def value timing? ? time : @value end
Private Instance Methods
extract_options!(options)
click to toggle source
# File lib/metrics/instrumenter.rb, line 74 def extract_options!(options) Metrics::Helpers.extract_options!(options) end
time()
click to toggle source
# File lib/metrics/instrumenter.rb, line 66 def time @time ||= begin start = Time.now result (Time.now - start) * 1000.0 end end
timing?()
click to toggle source
# File lib/metrics/instrumenter.rb, line 62 def timing? !block.nil? end