Class: TwemproxyExporter::Counter
- Inherits:
-
Object
- Object
- TwemproxyExporter::Counter
- Defined in:
- lib/twemproxy_exporter/counter.rb
Instance Method Summary collapse
- #count(value, labels = {}) ⇒ Object
-
#initialize(registry, name, desc) ⇒ Counter
constructor
A new instance of Counter.
- #value(labels = {}) ⇒ Object
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 |