Class: Librato::Metrics::Aggregator
- Inherits:
-
Object
- Object
- Librato::Metrics::Aggregator
- Includes:
- Processor
- Defined in:
- lib/librato/metrics/aggregator.rb
Overview
If you are measuring something very frequently you can sample into an aggregator and it will track and submit a single aggregate measurement
Constant Summary collapse
- SOURCE_SEPARATOR =
must not be in valid source name criteria
'%%'
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, #prefix
Instance Method Summary collapse
-
#add(measurements) ⇒ Aggregator
Add a metric entry to the metric set:.
-
#clear ⇒ Object
(also: #flush)
Remove all queued metrics.
-
#empty? ⇒ Boolean
Returns true if aggregate contains no measurements.
-
#initialize(opts = {}) ⇒ Aggregator
constructor
A new instance of Aggregator.
-
#queued ⇒ Object
Returns currently queued data.
Methods included from Processor
#client, #persister, #submit, #time
Constructor Details
#initialize(opts = {}) ⇒ Aggregator
Returns a new instance of Aggregator.
38 39 40 41 |
# File 'lib/librato/metrics/aggregator.rb', line 38 def initialize(opts={}) @aggregated = {} (opts) end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
30 31 32 |
# File 'lib/librato/metrics/aggregator.rb', line 30 def source @source end |
Instance Method Details
#add(measurements) ⇒ Aggregator
Add a metric entry to the metric set:
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/librato/metrics/aggregator.rb', line 53 def add(measurements) measurements.each do |metric, data| if @prefix metric = "#{@prefix}.#{metric}" end if data.respond_to?(:each) # hash form value = data[:value] if data[:source] metric = "#{metric}#{SOURCE_SEPARATOR}#{data[:source]}" end else value = data end @aggregated[metric] ||= Aggregate.new @aggregated[metric] << value end autosubmit_check self end |
#clear ⇒ Object Also known as: flush
Remove all queued metrics
83 84 85 |
# File 'lib/librato/metrics/aggregator.rb', line 83 def clear @aggregated = {} end |
#empty? ⇒ Boolean
Returns true if aggregate contains no measurements
77 78 79 |
# File 'lib/librato/metrics/aggregator.rb', line 77 def empty? @aggregated.empty? end |
#queued ⇒ Object
Returns currently queued data
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/librato/metrics/aggregator.rb', line 90 def queued gauges = [] @aggregated.each do |metric, data| source = nil metric = metric.to_s if metric.include?(SOURCE_SEPARATOR) metric, source = metric.split(SOURCE_SEPARATOR) end entry = { :name => metric, :count => data.count, :sum => data.sum, # TODO: make float/non-float consistent in the gem :min => data.min.to_f, :max => data.max.to_f # TODO: expose v.sum2 and include } entry[:source] = source if source gauges << entry end req = { :gauges => gauges } req[:source] = @source if @source req[:measure_time] = @measure_time if @measure_time req end |