Class: Cabin::Metrics::Counter

Inherits:
Object
  • Object
show all
Includes:
Cabin::Metric
Defined in:
lib/cabin/metrics/counter.rb

Instance Method Summary collapse

Methods included from Cabin::Metric

#emit, #instance, #instance=

Methods included from Publisher

#channel, #channel=, #publish

Methods included from Inspectable

#inspect

Constructor Details

#initializeCounter

Returns a new instance of Counter.



12
13
14
15
16
# File 'lib/cabin/metrics/counter.rb', line 12

def initialize
  @inspectables = [ :@value ]
  @value = 0
  @lock = Mutex.new
end

Instance Method Details

#decrObject

decrement this counter



25
26
27
28
# File 'lib/cabin/metrics/counter.rb', line 25

def decr
  @lock.synchronize { @value -= 1 }
  emit
end

#incrObject

increment this counter



19
20
21
22
# File 'lib/cabin/metrics/counter.rb', line 19

def incr
  @lock.synchronize { @value += 1 }
  emit
end

#to_hashObject



37
38
39
40
41
# File 'lib/cabin/metrics/counter.rb', line 37

def to_hash
  return @lock.synchronize do
    { :value => @value }
  end
end

#valueObject



32
33
34
# File 'lib/cabin/metrics/counter.rb', line 32

def value
  return @lock.synchronize { @value }
end