Class: Librato::Metrics::Queue
- Inherits:
-
Object
- Object
- Librato::Metrics::Queue
- Includes:
- Processor
- Defined in:
- lib/librato/metrics/queue.rb
Constant Summary
Constant Summary
Constants included from Processor
Processor::MEASUREMENTS_PER_REQUEST
Instance Attribute Summary (collapse)
-
- (Object) skip_measurement_times
Returns the value of attribute skip_measurement_times.
Attributes included from Processor
#last_submit_time, #per_request, #prefix
Instance Method Summary (collapse)
-
- (Queue) add(measurements)
Add a metric entry to the metric set:.
-
- (Object) clear
(also: #flush)
Remove all queued metrics.
-
- (Array) counters
Currently queued counters.
-
- (Boolean) empty?
Are any metrics currently queued?.
-
- (Object) gauges
Currently queued gauges.
-
- (Queue) initialize(options = {})
constructor
A new instance of Queue.
-
- (Object) merge!(mergeable)
Combines queueable measures from the given object into this queue.
-
- (Object) queued
All currently queued metrics.
-
- (Object) size
(also: #length)
Count of metrics currently queued.
Methods included from Processor
#client, #persister, #submit, #time
Constructor Details
- (Queue) initialize(options = {})
A new instance of Queue
10 11 12 13 14 15 |
# File 'lib/librato/metrics/queue.rb', line 10 def initialize(={}) @queued = {} @autosubmit_count = [:autosubmit_count] @skip_measurement_times = [:skip_measurement_times] () end |
Instance Attribute Details
- (Object) skip_measurement_times
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
- (Queue) add(measurements)
Add a metric entry to the metric set:
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/librato/metrics/queue.rb', line 21 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 |
- (Object) clear Also known as: flush
Remove all queued metrics
64 65 66 |
# File 'lib/librato/metrics/queue.rb', line 64 def clear @queued = {} end |
- (Array) counters
Currently queued counters
51 52 53 |
# File 'lib/librato/metrics/queue.rb', line 51 def counters @queued[:counters] || [] end |
- (Boolean) empty?
Are any metrics currently queued?
58 59 60 |
# File 'lib/librato/metrics/queue.rb', line 58 def empty? @queued.empty? end |
- (Object) gauges
Currently queued gauges
72 73 74 |
# File 'lib/librato/metrics/queue.rb', line 72 def gauges @queued[:gauges] || [] end |
- (Object) merge!(mergeable)
Combines queueable measures from the given object into this queue.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/librato/metrics/queue.rb', line 84 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 self end |
- (Object) queued
All currently queued metrics
108 109 110 111 112 113 114 |
# File 'lib/librato/metrics/queue.rb', line 108 def queued return {} if @queued.empty? globals = {} globals[:source] = @source if @source globals[:measure_time] = @measure_time if @measure_time @queued.merge(globals) end |
- (Object) size Also known as: length
Count of metrics currently queued
119 120 121 |
# File 'lib/librato/metrics/queue.rb', line 119 def size self.queued.inject(0) { |result, data| result + data.last.size } end |