Class: OpenTrace::Stats
- Inherits:
-
Object
- Object
- OpenTrace::Stats
- Defined in:
- lib/opentrace/stats.rb
Constant Summary collapse
- COUNTERS =
%i[ enqueued delivered dropped_queue_full dropped_circuit_open dropped_auth_suspended dropped_error dropped_filtered retries rate_limited auth_failures payload_splits batches_sent bytes_sent sampled_out sql_filtered ].freeze
Instance Method Summary collapse
- #get(counter) ⇒ Object
-
#increment(counter, amount = 1) ⇒ Object
Hot path: no mutex.
-
#initialize ⇒ Stats
constructor
A new instance of Stats.
- #reset! ⇒ Object
-
#to_h ⇒ Object
Cold path: mutex for consistent snapshot.
Constructor Details
Instance Method Details
#get(counter) ⇒ Object
35 36 37 |
# File 'lib/opentrace/stats.rb', line 35 def get(counter) @counters[counter] end |
#increment(counter, amount = 1) ⇒ Object
Hot path: no mutex. Under CRuby’s GIL, Hash#[]= with integer increment is effectively atomic for single operations.
31 32 33 |
# File 'lib/opentrace/stats.rb', line 31 def increment(counter, amount = 1) @counters[counter] += amount end |
#reset! ⇒ Object
46 47 48 49 50 51 |
# File 'lib/opentrace/stats.rb', line 46 def reset! @mutex.synchronize do @counters = Hash.new(0) @started_at = Time.now end end |
#to_h ⇒ Object
Cold path: mutex for consistent snapshot
40 41 42 43 44 |
# File 'lib/opentrace/stats.rb', line 40 def to_h @mutex.synchronize do @counters.merge(uptime_seconds: (Time.now - @started_at).to_i).dup end end |