Class: Deimos::Metrics::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/deimos/metrics/manager.rb

Constant Summary collapse

TYPES =
{
  counter: Prometheus::Client::Counter,
  gauge: Prometheus::Client::Gauge,
  histogram: Prometheus::Client::Histogram,
  summary: Prometheus::Client::Summary
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registry: Prometheus::Client.registry) ⇒ Manager

Returns a new instance of Manager.



14
15
16
# File 'lib/deimos/metrics/manager.rb', line 14

def initialize(registry: Prometheus::Client.registry)
  @registry = registry
end

Instance Attribute Details

#registryObject (readonly)

Returns the value of attribute registry.



13
14
15
# File 'lib/deimos/metrics/manager.rb', line 13

def registry
  @registry
end

Instance Method Details

#collectorsObject



18
19
20
# File 'lib/deimos/metrics/manager.rb', line 18

def collectors
  @collectors ||= {}
end

#subscribe(event_name, type:, label:, **kwargs, &block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/deimos/metrics/manager.rb', line 22

def subscribe(event_name, type:, label:, **kwargs, &block)
  Deimos.logger.info "Metrics: Subscribed to #{event_name}..."
  ActiveSupport::Notifications.subscribe(event_name) do |*args|
    event = ActiveSupport::Notifications::Event.new(*args)
    collector = register_collector!(event_name, type, label, kwargs)
    if block_given?
      yield(event, collector)
    else
      Deimos.logger.info event
    end
  end
end