Class: Protor::Accumulator

Inherits:
Object
  • Object
show all
Defined in:
lib/protor/accumulator.rb

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ Accumulator

Returns a new instance of Accumulator.



3
4
5
6
# File 'lib/protor/accumulator.rb', line 3

def initialize(type)
  @data = {}
  @type = type
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/protor/accumulator.rb', line 30

def empty?
  data.empty?
end

#inc(metric_name, value, labels = {}) ⇒ Object



8
9
10
11
# File 'lib/protor/accumulator.rb', line 8

def inc(metric_name, value, labels = {})
  data[metric_name] ||= Hash.new(0)
  data[metric_name][labels] += value
end

#set(metric_name, value, labels = {}) ⇒ Object



13
14
15
16
# File 'lib/protor/accumulator.rb', line 13

def set(metric_name, value, labels = {})
  data[metric_name] ||= Hash.new(0)
  data[metric_name][labels] = value
end

#to_aObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/protor/accumulator.rb', line 18

def to_a
  array = []

  data.each do |metric_name, values|
    values.each do |labels, value|
      array << { metric_name: metric_name, labels: labels, value: value, type: type }
    end
  end

  return array
end