Class: Metrics::Instrumenter
- Inherits:
-
Object
- Object
- Metrics::Instrumenter
- Defined in:
- lib/metrics/instrumenter.rb
Overview
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.
Constant Summary collapse
- TIME_UNITS =
'ms'.freeze
Instance Attribute Summary collapse
-
#metric ⇒ Object
readonly
Returns the value of attribute metric.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(metric, *args, &block) ⇒ Instrumenter
constructor
A new instance of Instrumenter.
- #result ⇒ Object
- #source ⇒ Object
- #tags ⇒ Object
- #type ⇒ Object
- #units ⇒ Object
-
#value ⇒ Object
Public: Runs the instrumenter.
Constructor Details
#initialize(metric, *args, &block) ⇒ Instrumenter
Returns a new instance of Instrumenter.
22 23 24 25 26 27 |
# File 'lib/metrics/instrumenter.rb', line 22 def initialize(metric, *args, &block) @metric = metric @options = (args) @block = block @value = args.first if args.length > 0 end |
Instance Attribute Details
#metric ⇒ Object (readonly)
Returns the value of attribute metric.
14 15 16 |
# File 'lib/metrics/instrumenter.rb', line 14 def metric @metric end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
14 15 16 |
# File 'lib/metrics/instrumenter.rb', line 14 def @options end |
Class Method Details
.instrument(*args, &block) ⇒ Object
16 17 18 19 20 |
# File 'lib/metrics/instrumenter.rb', line 16 def self.instrument(*args, &block) instrument = new(*args, &block) instrument.value instrument end |
Instance Method Details
#result ⇒ Object
53 54 55 56 57 |
# File 'lib/metrics/instrumenter.rb', line 53 def result return nil unless block return @result if defined?(@result) @result = block.call end |
#source ⇒ Object
45 46 47 |
# File 'lib/metrics/instrumenter.rb', line 45 def source [:source] end |
#tags ⇒ Object
49 50 51 |
# File 'lib/metrics/instrumenter.rb', line 49 def [:tags] || {} end |
#type ⇒ Object
41 42 43 |
# File 'lib/metrics/instrumenter.rb', line 41 def type [:type] || 'measure' end |
#units ⇒ Object
37 38 39 |
# File 'lib/metrics/instrumenter.rb', line 37 def units timing? ? TIME_UNITS : [:units] end |
#value ⇒ Object
Public: Runs the instrumenter.
Returns the run time if a block was supplied. Returns the value if the
33 34 35 |
# File 'lib/metrics/instrumenter.rb', line 33 def value timing? ? time : @value end |