Class: Cabin::Metrics::Histogram
- Inherits:
-
Object
- Object
- Cabin::Metrics::Histogram
show all
- Includes:
- Cabin::Metric
- Defined in:
- lib/cabin/metrics/histogram.rb
Direct Known Subclasses
Timer
Instance Method Summary
collapse
#emit, #instance, #instance=
Methods included from Publisher
#channel, #channel=, #publish
#inspect
Constructor Details
Returns a new instance of Histogram.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/cabin/metrics/histogram.rb', line 10
def initialize
@lock = Mutex.new
@inspectables = [ :@total, :@min, :@max, :@count, :@mean ]
@total = 0
@min = nil
@max = nil
@count = 0
@mean = 0.0
end
|
Instance Method Details
#record(value) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/cabin/metrics/histogram.rb', line 30
def record(value)
@lock.synchronize do
@count += 1
@total += value
if @min.nil? or value < @min
@min = value
end
if @max.nil? or value > @max
@max = value
end
@mean = @total / @count
end
emit
end
|
#to_hash ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/cabin/metrics/histogram.rb', line 55
def to_hash
return @lock.synchronize do
{
:count => @count,
:total => @total,
:min => @min,
:max => @max,
:mean => @mean,
}
end
end
|
#value ⇒ Object
50
51
52
|
# File 'lib/cabin/metrics/histogram.rb', line 50
def value
return @lock.synchronize { @count }
end
|