Class: Metrics::Grouping

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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, options = {}, &block)
  @instrumenters = []
  @namespace     = namespace
  @options       = options
  block.call(self)
end

Instance Attribute Details

#instrumentersObject (readonly)

Returns the value of attribute instrumenters.



5
6
7
# File 'lib/metrics/grouping.rb', line 5

def instrumenters
  @instrumenters
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



5
6
7
# File 'lib/metrics/grouping.rb', line 5

def namespace
  @namespace
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/metrics/grouping.rb', line 5

def options
  @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, *merge_options(args), &block))
end

#increment(metric) ⇒ Object



18
19
20
# File 'lib/metrics/grouping.rb', line 18

def increment(metric)
  instrument metric, 1, options.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, *merge_options(args), &block))
end