Module: SimpleMetrics::DataPoint
- Extended by:
- DataPoint
- Included in:
- DataPoint
- Defined in:
- lib/simple_metrics/data_point.rb,
lib/simple_metrics/data_point/base.rb,
lib/simple_metrics/data_point/event.rb,
lib/simple_metrics/data_point/gauge.rb,
lib/simple_metrics/data_point/timing.rb,
lib/simple_metrics/data_point/counter.rb
Defined Under Namespace
Classes: Base, Counter, Event, Gauge, NonMatchingTypesError, ParserError, Timing, UnknownTypeError
Constant Summary
collapse
- REGEXP =
examples: com.example.test1:1|c com.example.test2:-1|c com.example.test2:50|g com.example.test3:5|c|@0.1 com.example.test4:44|ms
/^([\d\w_.]*):(-?[\d]*)\|(c|g|ms){1}(\|@([.\d]+))?$/i
Instance Method Summary
collapse
Instance Method Details
#aggregate_values(dps) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/simple_metrics/data_point.rb', line 41
def aggregate_values(dps)
raise SimpleMetrics::DataPoint::NonMatchingTypesError if has_non_matching_types?(dps)
dp = dps.first.dup
dp.value = if dp.counter?
sum(dps)
elsif dp.gauge?
sum(dps) / dps.size
elsif dp.event?
raise "Implement me!"
elsif dp.timing?
raise "Implement me!"
else
raise ArgumentError("Unknown data point type: #{dp}")
end
dp
end
|
#build(attributes) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/simple_metrics/data_point.rb', line 26
def build(attributes)
case attributes[:type]
when 'c'
Counter.new(attributes)
when 'g'
Gauge.new(attributes)
when 'ms'
Timing.new(attributes)
when 'ev'
Event.new(attributes)
else
raise UnknownTypeError, "Unknown Type Error: #{attributes[:type]}"
end
end
|
#parse(str) ⇒ Object
17
18
19
20
21
22
23
24
|
# File 'lib/simple_metrics/data_point.rb', line 17
def parse(str)
if str =~ REGEXP
name, value, type, sample_rate = $1, $2, $3, $5
build(:name => name, :value => value, :type => type, :sample_rate => sample_rate)
else
raise ParserError, "Parser Error - Invalid data point: #{str}"
end
end
|