Class: TwemproxyExporter::Counter

Inherits:
Object
  • Object
show all
Defined in:
lib/twemproxy_exporter/counter.rb

Instance Method Summary collapse

Constructor Details

#initialize(registry, name, desc) ⇒ Counter

Returns a new instance of Counter.



3
4
5
6
7
# File 'lib/twemproxy_exporter/counter.rb', line 3

def initialize(registry, name, desc)
  @counter = Prometheus::Client::Counter.new(name, desc)
  registry.register(@counter)
  @last = 0
end

Instance Method Details

#count(value, labels = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/twemproxy_exporter/counter.rb', line 9

def count(value, labels = {})
  if value >= @last
    @counter.increment(labels, value - @last)
  else
    @counter.increment(labels, value)
  end

  @last = value
end

#value(labels = {}) ⇒ Object



19
20
21
# File 'lib/twemproxy_exporter/counter.rb', line 19

def value(labels = {})
  @counter.get(labels)
end