Class: TingYun::Metrics::MetricData
- Inherits:
-
Object
- Object
- TingYun::Metrics::MetricData
show all
- Includes:
- Support::Coerce
- Defined in:
- lib/ting_yun/metrics/metric_data.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
event_params, float, int, int_or_nil, log_failure, string
Constructor Details
#initialize(metric_spec, stats, metric_id) ⇒ MetricData
Returns a new instance of MetricData.
17
18
19
20
21
|
# File 'lib/ting_yun/metrics/metric_data.rb', line 17
def initialize(metric_spec, stats, metric_id)
@metric_spec = metric_spec
self.stats = stats
self.metric_id = metric_id
end
|
Instance Attribute Details
#metric_id ⇒ Object
nil or a cached integer ID for the metric from the collector.
13
14
15
|
# File 'lib/ting_yun/metrics/metric_data.rb', line 13
def metric_id
@metric_id
end
|
#metric_spec ⇒ Object
nil, or a TingYun::Metrics::MetricSpec object if we have no cached ID
11
12
13
|
# File 'lib/ting_yun/metrics/metric_data.rb', line 11
def metric_spec
@metric_spec
end
|
#stats ⇒ Object
the actual statistics object
15
16
17
|
# File 'lib/ting_yun/metrics/metric_data.rb', line 15
def stats
@stats
end
|
Instance Method Details
#eql?(o) ⇒ Boolean
23
24
25
|
# File 'lib/ting_yun/metrics/metric_data.rb', line 23
def eql?(o)
(metric_spec.eql? o.metric_spec) && (stats.eql? o.stats)
end
|
#hash ⇒ Object
27
28
29
|
# File 'lib/ting_yun/metrics/metric_data.rb', line 27
def hash
metric_spec.hash ^ stats.hash
end
|
#inspect ⇒ Object
44
45
46
|
# File 'lib/ting_yun/metrics/metric_data.rb', line 44
def inspect
"#<MetricData metric_spec:#{metric_spec.inspect}, stats:#{stats.inspect}, metric_id:#{metric_id.inspect}>"
end
|
#metrics(stat_key) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/ting_yun/metrics/metric_data.rb', line 66
def metrics(stat_key)
metrics = []
metrics << int(stats.call_count, stat_key)
if stats.max_call_time != 0.0
metrics << float(stats.total_call_time, stat_key)
metrics << float(stats.total_exclusive_time, stat_key)
metrics << float(stats.max_call_time, stat_key)
end
if stats.min_call_time !=0.0
metrics << float(stats.min_call_time, stat_key)
metrics << float(stats.sum_of_squares, stat_key)
end
metrics
end
|
#stats_has_parent? ⇒ Boolean
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/ting_yun/metrics/metric_data.rb', line 55
def stats_has_parent?
hash = { 'name' => metric_spec.name }
hash['calleeId'] = metric_spec.calleeId unless metric_spec.calleeId.nil?
hash['calleeName'] = metric_spec.calleeName unless metric_spec.calleeName.nil?
unless metric_spec.scope.empty?
hash['parent'] = metric_spec.scope
end
return hash
end
|
#to_collector_array(encoder = nil) ⇒ Object
50
51
52
53
|
# File 'lib/ting_yun/metrics/metric_data.rb', line 50
def to_collector_array(encoder=nil)
stat_key = metric_id || stats_has_parent?
[ stat_key,metrics(stat_key)]
end
|
#to_json(*a) ⇒ Object
Serialize with all attributes, but if the metric id is not nil, then don’t send the metric spec
32
33
34
|
# File 'lib/ting_yun/metrics/metric_data.rb', line 32
def to_json(*a)
%Q[{"metric_spec":#{metric_id ? 'null' : metric_spec.to_json},"stats":{"total_exclusive_time":#{stats.total_exclusive_time},"min_call_time":#{stats.min_call_time},"call_count":#{stats.call_count},"sum_of_squares":#{stats.sum_of_squares},"total_call_time":#{stats.total_call_time},"max_call_time":#{stats.max_call_time}},"metric_id":#{metric_id ? metric_id : 'null'}}]
end
|
#to_s ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/ting_yun/metrics/metric_data.rb', line 36
def to_s
if metric_spec
"#{metric_spec.name}(#{metric_spec.scope}): #{stats}"
else
"#{metric_id}: #{stats}"
end
end
|