Class: Metriks::Counter

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

Overview

Public: Counters are one of the simplest metrics whose only operations are increment and decrement.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCounter

Public: Initialize a new Counter.



10
11
12
# File 'lib/metriks/counter.rb', line 10

def initialize
  @count = Atomic.new(0)
end

Instance Attribute Details

#reset_on_submitObject

sometimes I have multiple processes that count values, so I need to reset every time after submit



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

def reset_on_submit
  @reset_on_submit
end

Instance Method Details

#clearObject

Public: Reset the counter back to 0

Returns nothing.



17
18
19
# File 'lib/metriks/counter.rb', line 17

def clear
  @count.value = 0
end

#countObject

Public: The current count.

Returns the count.



42
43
44
# File 'lib/metriks/counter.rb', line 42

def count
  @count.value
end

#decrement(decr = 1) ⇒ Object

Public: Decrement the counter.

decr - The value to subtract from the counter.

Returns nothing.



35
36
37
# File 'lib/metriks/counter.rb', line 35

def decrement(decr = 1)
  @count.update { |v| v - decr }
end

#increment(incr = 1) ⇒ Object

Public: Increment the counter.

incr - The value to add to the counter.

Returns nothing.



26
27
28
# File 'lib/metriks/counter.rb', line 26

def increment(incr = 1)
  @count.update { |v| v + incr }
end