Class: Cabin::Metrics::Meter

Inherits:
Object
  • Object
show all
Includes:
Inspectable
Defined in:
lib/cabin/metrics/meter.rb

Instance Method Summary collapse

Methods included from Inspectable

#inspect

Constructor Details

#initializeMeter

Returns a new instance of Meter.



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

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

Instance Method Details

#markObject

Mark an event



19
20
21
22
23
24
# File 'lib/cabin/metrics/meter.rb', line 19

def mark
  @lock.synchronize do
    @value += 1
    # TODO(sissel): Keep some moving averages?
  end
end

#to_hashObject



33
34
35
36
37
# File 'lib/cabin/metrics/meter.rb', line 33

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

#valueObject



28
29
30
# File 'lib/cabin/metrics/meter.rb', line 28

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