Class: FlowChat::Instrumentation::MetricsCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/flow_chat/instrumentation/metrics_collector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMetricsCollector

Returns a new instance of MetricsCollector.



6
7
8
9
10
# File 'lib/flow_chat/instrumentation/metrics_collector.rb', line 6

def initialize
  @metrics = {}
  @mutex = Mutex.new
  subscribe_to_events
end

Instance Attribute Details

#metricsObject (readonly)

Returns the value of attribute metrics.



4
5
6
# File 'lib/flow_chat/instrumentation/metrics_collector.rb', line 4

def metrics
  @metrics
end

Instance Method Details

#get_category(category) ⇒ Object

Get metrics for a specific category



23
24
25
26
27
# File 'lib/flow_chat/instrumentation/metrics_collector.rb', line 23

def get_category(category)
  @mutex.synchronize do
    @metrics.select { |key, _| key.to_s.start_with?("#{category}.") }
  end
end

#reset!Object

Reset all metrics



18
19
20
# File 'lib/flow_chat/instrumentation/metrics_collector.rb', line 18

def reset!
  @mutex.synchronize { @metrics.clear }
end

#snapshotObject

Get current metrics snapshot



13
14
15
# File 'lib/flow_chat/instrumentation/metrics_collector.rb', line 13

def snapshot
  @mutex.synchronize { @metrics.dup }
end