Class: Cabin::Metrics::Meter

Inherits:
Object
  • Object
show all
Includes:
Cabin::Metric
Defined in:
lib/cabin/metrics/meter.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

#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
25
# File 'lib/cabin/metrics/meter.rb', line 19

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

#to_hashObject



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

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

#valueObject



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

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