Class: LogStash::Instrument::MetricType::Mean
- Inherits:
-
Base
- Object
- Base
- LogStash::Instrument::MetricType::Mean
show all
- Defined in:
- lib/logstash/instrument/metric_type/mean.rb
Instance Attribute Summary
Attributes inherited from Base
#key, #namespaces
Instance Method Summary
collapse
Methods inherited from Base
#inspect, #to_hash, #to_json_data, #type
Constructor Details
#initialize(namespaces, key) ⇒ Mean
Returns a new instance of Mean.
7
8
9
10
11
12
|
# File 'lib/logstash/instrument/metric_type/mean.rb', line 7
def initialize(namespaces, key)
super(namespaces, key)
@counter = Concurrent::AtomicFixnum.new
@sum = Concurrent::AtomicFixnum.new
end
|
Instance Method Details
#decrement(value = 1) ⇒ Object
19
20
21
22
|
# File 'lib/logstash/instrument/metric_type/mean.rb', line 19
def decrement(value = 1)
@counter.decrement
@sum.decrement(value)
end
|
#increment(value = 1) ⇒ Object
14
15
16
17
|
# File 'lib/logstash/instrument/metric_type/mean.rb', line 14
def increment(value = 1)
@counter.increment
@sum.increment(value)
end
|
#mean ⇒ Object
Also known as:
value
24
25
26
27
28
29
30
|
# File 'lib/logstash/instrument/metric_type/mean.rb', line 24
def mean
if @counter > 0
@sum.value / @counter.value
else
0
end
end
|