Exception: SplitIoClient::Metrics
- Inherits:
-
NoMethodError
- Object
- NoMethodError
- SplitIoClient::Metrics
- Defined in:
- lib/engine/metrics/metrics.rb
Overview
class to handle cached metrics
Instance Attribute Summary collapse
-
#counts ⇒ object
cached counts.
-
#gauges ⇒ object
cached gauges.
-
#latencies ⇒ object
cached latencies.
-
#queue_size ⇒ int
quese size for cached arrays.
Instance Method Summary collapse
-
#count(counter, delta) ⇒ Object
creates a new entry in the array for cached counts.
-
#gauge(gauge, value) ⇒ Object
creates a new entry in the array for cached gauges.
-
#initialize(queue_size) ⇒ Metrics
constructor
A new instance of Metrics.
-
#time(operation, time_in_ms) ⇒ Object
creates a new entry in the array for cached time metrics.
Constructor Details
#initialize(queue_size) ⇒ Metrics
Returns a new instance of Metrics.
35 36 37 38 39 40 41 |
# File 'lib/engine/metrics/metrics.rb', line 35 def initialize(queue_size) @latencies = [] @counts = [] @gauges = [] @queue_size = queue_size @binary_search = SplitIoClient::BinarySearchLatencyTracker.new end |
Instance Attribute Details
#counts ⇒ object
cached counts
21 22 23 |
# File 'lib/engine/metrics/metrics.rb', line 21 def counts @counts end |
#gauges ⇒ object
cached gauges
27 28 29 |
# File 'lib/engine/metrics/metrics.rb', line 27 def gauges @gauges end |
#latencies ⇒ object
cached latencies
15 16 17 |
# File 'lib/engine/metrics/metrics.rb', line 15 def latencies @latencies end |
#queue_size ⇒ int
quese size for cached arrays
33 34 35 |
# File 'lib/engine/metrics/metrics.rb', line 33 def queue_size @queue_size end |
Instance Method Details
#count(counter, delta) ⇒ Object
creates a new entry in the array for cached counts
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/engine/metrics/metrics.rb', line 50 def count(counter, delta) return if delta <= 0 return if (counter.nil? || counter.strip.empty?) counter_hash = @counts.find { |c| c[:name] == counter } if counter_hash.nil? counter_delta = SumAndCount.new counter_delta.add_delta(delta) @counts << {name: counter, delta: counter_delta} else counter_hash[:delta].add_delta(delta) end end |
#gauge(gauge, value) ⇒ Object
creates a new entry in the array for cached gauges
94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/engine/metrics/metrics.rb', line 94 def gauge(gauge, value) if gauge.nil? || gauge.empty? return end gauge_hash = @gauges.find { |g| g[:name] == gauge } if gauge_hash.nil? gauge_value = ValueAndCount.new gauge_value.set_value(value) @gauges << {name: gauge, value: gauge_value} else gauge_hash[:value].set_value(value) end end |
#time(operation, time_in_ms) ⇒ Object
creates a new entry in the array for cached time metrics
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/engine/metrics/metrics.rb', line 72 def time(operation, time_in_ms) if operation.nil? || operation.empty? || time_in_ms < 0 return; end operation_hash = @latencies.find { |l| l[:operation] == operation } if operation_hash.nil? latencies_for_op = (operation == 'sdk.get_treatment') ? @binary_search.add_latency_millis(time_in_ms) : [time_in_ms] @latencies << {operation: operation, latencies: latencies_for_op} else latencies_for_op = (operation == 'sdk.get_treatment') ? @binary_search.add_latency_millis(time_in_ms) : operation_hash[:latencies].push(time_in_ms) end end |