Class: PhobosPrometheus::Collector::Counter

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/phobos_prometheus/collector/counter.rb

Overview

Collector class to track counter events

Instance Attribute Summary collapse

Attributes included from Helper

#registry

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helper

#safely_update_metrics, #setup_collector_module, #subscribe_metrics

Constructor Details

#initialize(instrumentation:) ⇒ Counter

Returns a new instance of Counter.



17
18
19
20
# File 'lib/phobos_prometheus/collector/counter.rb', line 17

def initialize(instrumentation:)
  @metrics_prefix = @instrumentation = @registry = @counter = nil
  setup_collector_module(instrumentation: instrumentation)
end

Instance Attribute Details

#counterObject (readonly)

Returns the value of attribute counter.



8
9
10
# File 'lib/phobos_prometheus/collector/counter.rb', line 8

def counter
  @counter
end

Class Method Details

.create(config) ⇒ Object



10
11
12
13
14
15
# File 'lib/phobos_prometheus/collector/counter.rb', line 10

def self.create(config)
  instrumentation = config[:instrumentation]
  raise(InvalidConfigurationError, 'Counter requires :instrumentation') \
    unless instrumentation
  new(instrumentation: instrumentation)
end

Instance Method Details

#init_metrics(prometheus_label) ⇒ Object



22
23
24
25
26
27
# File 'lib/phobos_prometheus/collector/counter.rb', line 22

def init_metrics(prometheus_label)
  @counter = @registry.counter(
    :"#{@metrics_prefix}_#{prometheus_label}_total",
    "The total number of #{@instrumentation} events handled."
  )
end

#update_metrics(event_label, _event) ⇒ Object



29
30
31
# File 'lib/phobos_prometheus/collector/counter.rb', line 29

def update_metrics(event_label, _event)
  @counter.increment(event_label)
end