Class: Librato::Metrics::Aggregator
- Inherits:
-
Object
- Object
- Librato::Metrics::Aggregator
- Includes:
- Processor
- Defined in:
- lib/librato/metrics/aggregator.rb
Constant Summary
Constants included from Processor
Processor::MEASUREMENTS_PER_REQUEST
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Attributes included from Processor
#last_submit_time, #per_request
Instance Method Summary collapse
-
#add(args) ⇒ Object
Add a metric entry to the metric set:.
-
#empty? ⇒ Boolean
Returns true if aggregate contains no measurements.
-
#flush ⇒ Object
(also: #clear)
Remove all queued metrics.
-
#initialize(options = {}) ⇒ Aggregator
constructor
A new instance of Aggregator.
- #queued ⇒ Object
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(={}) @aggregated = {} () end |
Instance Attribute Details
#source ⇒ Object (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:
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
35 36 37 |
# File 'lib/librato/metrics/aggregator.rb', line 35 def empty? @aggregated.empty? end |
#flush ⇒ Object Also known as: clear
Remove all queued metrics
41 42 43 |
# File 'lib/librato/metrics/aggregator.rb', line 41 def flush @aggregated = {} end |
#queued ⇒ Object
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 |