Class: Metrics::Grouping

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

Methods included from StatsdApi

#count, #decrement, #gauge, #histogram, #time, #timing

Constructor Details

#initialize(namespace = nil, options = {}, &block) ⇒ Grouping



13
14
15
16
17
18
# File 'lib/metrics/grouping.rb', line 13

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.



7
8
9
# File 'lib/metrics/grouping.rb', line 7

def instrumenters
  @instrumenters
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



7
8
9
# File 'lib/metrics/grouping.rb', line 7

def namespace
  @namespace
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/metrics/grouping.rb', line 7

def options
  @options
end

Class Method Details

.instrument(namespace = nil, options = {}, &block) ⇒ Object



9
10
11
# File 'lib/metrics/grouping.rb', line 9

def self.instrument(namespace = nil, options = {}, &block)
  new(namespace, options, &block).instrumenters
end

Instance Method Details

#group(nested_namespace = nil, *args, &block) ⇒ Object



29
30
31
32
# File 'lib/metrics/grouping.rb', line 29

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



20
21
22
# File 'lib/metrics/grouping.rb', line 20

def increment(metric)
  super(metric, options)
end

#instrument(metric, *args, &block) ⇒ Object



24
25
26
27
# File 'lib/metrics/grouping.rb', line 24

def instrument(metric, *args, &block)
  metric = "#{namespace}.#{metric}" if namespace
  instrumenters.push(Instrumenter.instrument(metric, *merge_options(args), &block))
end