Class: Flagstack::Telemetry::MetricStorage
- Inherits:
-
Object
- Object
- Flagstack::Telemetry::MetricStorage
- Defined in:
- lib/flagstack/telemetry/metric_storage.rb
Instance Method Summary collapse
- #drain ⇒ Object
- #empty? ⇒ Boolean
- #increment(metric) ⇒ Object
-
#initialize ⇒ MetricStorage
constructor
A new instance of MetricStorage.
- #size ⇒ Object
Constructor Details
#initialize ⇒ MetricStorage
Returns a new instance of MetricStorage.
4 5 6 7 |
# File 'lib/flagstack/telemetry/metric_storage.rb', line 4 def initialize @mutex = Mutex.new @storage = Hash.new(0) end |
Instance Method Details
#drain ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/flagstack/telemetry/metric_storage.rb', line 15 def drain @mutex.synchronize do metrics = @storage.dup @storage.clear metrics.freeze end end |
#empty? ⇒ Boolean
23 24 25 |
# File 'lib/flagstack/telemetry/metric_storage.rb', line 23 def empty? @mutex.synchronize { @storage.empty? } end |
#increment(metric) ⇒ Object
9 10 11 12 13 |
# File 'lib/flagstack/telemetry/metric_storage.rb', line 9 def increment(metric) @mutex.synchronize do @storage[metric] += 1 end end |
#size ⇒ Object
27 28 29 |
# File 'lib/flagstack/telemetry/metric_storage.rb', line 27 def size @mutex.synchronize { @storage.size } end |