Class: Metrics::Grouping
- Inherits:
-
Object
- Object
- Metrics::Grouping
- Defined in:
- lib/metrics/grouping.rb
Overview
Public: Starts a new Grouping context, which allows for multiple instruments to output on a single line.
Instance Attribute Summary collapse
-
#instrumenters ⇒ Object
readonly
Returns the value of attribute instrumenters.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #group(nested_namespace = nil, *args, &block) ⇒ Object
- #increment(metric) ⇒ Object
-
#initialize(namespace = nil, options = {}, &block) ⇒ Grouping
constructor
A new instance of Grouping.
- #instrument(metric, *args, &block) ⇒ Object
Constructor Details
#initialize(namespace = nil, options = {}, &block) ⇒ Grouping
Returns a new instance of Grouping.
11 12 13 14 15 16 |
# File 'lib/metrics/grouping.rb', line 11 def initialize(namespace = nil, = {}, &block) @instrumenters = [] @namespace = namespace @options = block.call(self) end |
Instance Attribute Details
#instrumenters ⇒ Object (readonly)
Returns the value of attribute instrumenters.
5 6 7 |
# File 'lib/metrics/grouping.rb', line 5 def instrumenters @instrumenters end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
5 6 7 |
# File 'lib/metrics/grouping.rb', line 5 def namespace @namespace end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/metrics/grouping.rb', line 5 def @options end |
Class Method Details
.instrument(*args, &block) ⇒ Object
7 8 9 |
# File 'lib/metrics/grouping.rb', line 7 def self.instrument(*args, &block) new(*args, &block).instrumenters end |
Instance Method Details
#group(nested_namespace = nil, *args, &block) ⇒ Object
27 28 29 30 |
# File 'lib/metrics/grouping.rb', line 27 def group(nested_namespace = nil, *args, &block) ns = nested_namespace ? "#{namespace}.#{nested_namespace}" : namespace instrumenters.push(*Grouping.instrument(ns, *(args), &block)) end |
#increment(metric) ⇒ Object
18 19 20 |
# File 'lib/metrics/grouping.rb', line 18 def increment(metric) instrument metric, 1, .merge(type: 'count') end |
#instrument(metric, *args, &block) ⇒ Object
22 23 24 25 |
# File 'lib/metrics/grouping.rb', line 22 def instrument(metric, *args, &block) metric = "#{namespace}.#{metric}" if namespace instrumenters.push(Instrumenter.instrument(metric, *(args), &block)) end |