Class: Librato::Metrics::Aggregator

Inherits:
Object
  • Object
show all
Includes:
Processor
Defined in:
lib/librato/metrics/aggregator.rb

Constant Summary

Constants included from Processor

Processor::MEASUREMENTS_PER_REQUEST

Instance Attribute Summary collapse

Attributes included from Processor

#last_submit_time, #per_request

Instance Method Summary collapse

Methods included from Processor

#client, #persister, #submit, #time

Constructor Details

#initialize(options = {}) ⇒ Aggregator

Returns a new instance of Aggregator.



12
13
14
15
# File 'lib/librato/metrics/aggregator.rb', line 12

def initialize(options={})
  @aggregated = {}
  setup_common_options(options)
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



10
11
12
# File 'lib/librato/metrics/aggregator.rb', line 10

def source
  @source
end

Instance Method Details

#add(args) ⇒ Object

Add a metric entry to the metric set:

Parameters:

  • Hash

    metrics metrics to add

Returns:

  • Aggregator returns self



21
22
23
24
25
26
27
28
29
30
# File 'lib/librato/metrics/aggregator.rb', line 21

def add(args)
  args.each do |k, v|
    value = v.respond_to?(:each) ? v[:value] : v

    @aggregated[k] ||= Aggregate.new
    @aggregated[k] << value
  end
  autosubmit_check
  self
end

#empty?Boolean

Returns true if aggregate contains no measurements

Returns:

  • (Boolean)

    Boolean



35
36
37
# File 'lib/librato/metrics/aggregator.rb', line 35

def empty?
  @aggregated.empty?
end

#flushObject Also known as: clear

Remove all queued metrics



41
42
43
# File 'lib/librato/metrics/aggregator.rb', line 41

def flush
  @aggregated = {}
end

#queuedObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/librato/metrics/aggregator.rb', line 46

def queued
  gauges = []

  @aggregated.each do |k,v|
    gauges << {
      :name => k.to_s,
      :count => v.count,
      :sum => v.sum,

      # TODO: make float/non-float consistent in the gem
      :min => v.min.to_f,
      :max => v.max.to_f
      # TODO: expose v.sum2 and include
    }
  end

  req = { :gauges => gauges }
  req[:source] = @source if @source

  req
end