Class: Librato::Metrics::Queue
- Inherits:
-
Object
- Object
- Librato::Metrics::Queue
- Includes:
- Processor
- Defined in:
- lib/librato/metrics/queue.rb
Constant Summary
Constants included from Processor
Processor::MEASUREMENTS_PER_REQUEST
Instance Attribute Summary collapse
-
#skip_measurement_times ⇒ Object
Returns the value of attribute skip_measurement_times.
Attributes included from Processor
#last_submit_time, #per_request, #prefix
Instance Method Summary collapse
-
#add(measurements) ⇒ Queue
Add a metric entry to the metric set:.
-
#clear ⇒ Object
(also: #flush)
Remove all queued metrics.
-
#counters ⇒ Array
Currently queued counters.
-
#empty? ⇒ Boolean
Are any metrics currently queued?.
-
#gauges ⇒ Object
Currently queued gauges.
-
#initialize(opts = {}) ⇒ Queue
constructor
A new instance of Queue.
-
#merge!(mergeable) ⇒ Object
Combines queueable measures from the given object into this queue.
-
#queued ⇒ Object
All currently queued metrics.
-
#size ⇒ Object
(also: #length)
Count of metrics currently queued.
Methods included from Processor
#client, #persister, #submit, #time
Constructor Details
#initialize(opts = {}) ⇒ Queue
Returns a new instance of Queue.
18 19 20 21 22 23 |
# File 'lib/librato/metrics/queue.rb', line 18 def initialize(opts={}) @queued = {} @autosubmit_count = opts[:autosubmit_count] @skip_measurement_times = opts[:skip_measurement_times] (opts) end |
Instance Attribute Details
#skip_measurement_times ⇒ Object
Returns the value of attribute skip_measurement_times.
8 9 10 |
# File 'lib/librato/metrics/queue.rb', line 8 def skip_measurement_times @skip_measurement_times end |
Instance Method Details
#add(measurements) ⇒ Queue
Add a metric entry to the metric set:
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/librato/metrics/queue.rb', line 29 def add(measurements) measurements.each do |key, value| if value.respond_to?(:each) metric = value metric[:name] = key.to_s type = metric.delete(:type) || metric.delete('type') || 'gauge' else metric = {:name => key.to_s, :value => value} type = :gauge end if @prefix metric[:name] = "#{@prefix}.#{metric[:name]}" end type = ("#{type}s").to_sym if metric[:measure_time] metric[:measure_time] = metric[:measure_time].to_i check_measure_time(metric) elsif !skip_measurement_times metric[:measure_time] = epoch_time end @queued[type] ||= [] @queued[type] << metric end submit_check self end |
#clear ⇒ Object Also known as: flush
Remove all queued metrics
72 73 74 |
# File 'lib/librato/metrics/queue.rb', line 72 def clear @queued = {} end |
#counters ⇒ Array
Currently queued counters
59 60 61 |
# File 'lib/librato/metrics/queue.rb', line 59 def counters @queued[:counters] || [] end |
#empty? ⇒ Boolean
Are any metrics currently queued?
66 67 68 |
# File 'lib/librato/metrics/queue.rb', line 66 def empty? @queued.empty? end |
#gauges ⇒ Object
Currently queued gauges
80 81 82 |
# File 'lib/librato/metrics/queue.rb', line 80 def gauges @queued[:gauges] || [] end |
#merge!(mergeable) ⇒ Object
Combines queueable measures from the given object into this queue.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/librato/metrics/queue.rb', line 92 def merge!(mergeable) if mergeable.respond_to?(:queued) to_merge = mergeable.queued elsif mergeable.respond_to?(:has_key?) to_merge = mergeable else raise NotMergeable end Metrics::PLURAL_TYPES.each do |type| if to_merge[type] measurements = reconcile_source(to_merge[type], to_merge[:source]) if @queued[type] @queued[type] += measurements else @queued[type] = measurements end end end submit_check self end |
#queued ⇒ Object
All currently queued metrics
117 118 119 120 121 122 123 |
# File 'lib/librato/metrics/queue.rb', line 117 def queued return {} if @queued.empty? globals = {} globals[:source] = @source if @source globals[:measure_time] = @measure_time if @measure_time @queued.merge(globals) end |
#size ⇒ Object Also known as: length
Count of metrics currently queued
128 129 130 |
# File 'lib/librato/metrics/queue.rb', line 128 def size self.queued.inject(0) { |result, data| result + data.last.size } end |