Class: NewRelic::Agent::Stats
- Inherits:
-
Object
- Object
- NewRelic::Agent::Stats
- Defined in:
- lib/new_relic/agent/stats.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#call_count ⇒ Object
(also: #apdex_s)
Returns the value of attribute call_count.
-
#max_call_time ⇒ Object
Returns the value of attribute max_call_time.
-
#min_call_time ⇒ Object
Returns the value of attribute min_call_time.
-
#sum_of_squares ⇒ Object
Returns the value of attribute sum_of_squares.
-
#total_call_time ⇒ Object
(also: #apdex_t)
Returns the value of attribute total_call_time.
-
#total_exclusive_time ⇒ Object
(also: #apdex_f)
Returns the value of attribute total_exclusive_time.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#increment_count(value = 1) ⇒ Object
increments the call_count by one.
-
#initialize ⇒ Stats
constructor
A new instance of Stats.
- #inspect ⇒ Object
-
#inspect_full ⇒ Object
Concerned about implicit usage of inspect relying on stats format, so putting back a version to get full inspection as separate method.
- #is_reset? ⇒ Boolean
- #merge(other_stats) ⇒ Object
- #merge!(other_stats) ⇒ Object
- #record_apdex(bucket, apdex_t) ⇒ Object
-
#record_data_point(value, exclusive_time = value) ⇒ Object
(also: #trace_call)
record a single data point into the statistical gatherer.
-
#record_multiple_data_points(total_value, count = 1) ⇒ Object
Records multiple data points as one method call - this handles all the aggregation that would be done with multiple record_data_point calls.
- #reset ⇒ Object
- #to_json(*_) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Stats
Returns a new instance of Stats.
14 15 16 |
# File 'lib/new_relic/agent/stats.rb', line 14 def initialize reset end |
Instance Attribute Details
#call_count ⇒ Object Also known as: apdex_s
Returns the value of attribute call_count.
7 8 9 |
# File 'lib/new_relic/agent/stats.rb', line 7 def call_count @call_count end |
#max_call_time ⇒ Object
Returns the value of attribute max_call_time.
9 10 11 |
# File 'lib/new_relic/agent/stats.rb', line 9 def max_call_time @max_call_time end |
#min_call_time ⇒ Object
Returns the value of attribute min_call_time.
8 9 10 |
# File 'lib/new_relic/agent/stats.rb', line 8 def min_call_time @min_call_time end |
#sum_of_squares ⇒ Object
Returns the value of attribute sum_of_squares.
12 13 14 |
# File 'lib/new_relic/agent/stats.rb', line 12 def sum_of_squares @sum_of_squares end |
#total_call_time ⇒ Object Also known as: apdex_t
Returns the value of attribute total_call_time.
10 11 12 |
# File 'lib/new_relic/agent/stats.rb', line 10 def total_call_time @total_call_time end |
#total_exclusive_time ⇒ Object Also known as: apdex_f
Returns the value of attribute total_exclusive_time.
11 12 13 |
# File 'lib/new_relic/agent/stats.rb', line 11 def total_exclusive_time @total_exclusive_time end |
Instance Method Details
#==(other) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/new_relic/agent/stats.rb', line 112 def ==(other) other.class == self.class && ( @min_call_time == other.min_call_time && @max_call_time == other.max_call_time && @total_call_time == other.total_call_time && @total_exclusive_time == other.total_exclusive_time && @sum_of_squares == other.sum_of_squares && @call_count == other.call_count ) end |
#increment_count(value = 1) ⇒ Object
increments the call_count by one
95 96 97 |
# File 'lib/new_relic/agent/stats.rb', line 95 def increment_count(value = 1) @call_count += value end |
#inspect ⇒ Object
99 100 101 |
# File 'lib/new_relic/agent/stats.rb', line 99 def inspect "#<NewRelic::Agent::Stats #{to_s} >" end |
#inspect_full ⇒ Object
Concerned about implicit usage of inspect relying on stats format, so putting back a version to get full inspection as separate method
105 106 107 108 109 110 |
# File 'lib/new_relic/agent/stats.rb', line 105 def inspect_full variables = instance_variables.map do |ivar| "#{ivar.to_s}=#{instance_variable_get(ivar).inspect}" end.join(" ") "#<NewRelic::Agent::Stats #{variables}>" end |
#is_reset? ⇒ Boolean
27 28 29 |
# File 'lib/new_relic/agent/stats.rb', line 27 def is_reset? call_count == 0 && total_call_time == 0.0 && total_exclusive_time == 0.0 end |
#merge(other_stats) ⇒ Object
31 32 33 34 |
# File 'lib/new_relic/agent/stats.rb', line 31 def merge(other_stats) stats = self.clone stats.merge!(other_stats) end |
#merge!(other_stats) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/new_relic/agent/stats.rb', line 36 def merge!(other_stats) Array(other_stats).each do |other| @min_call_time = other.min_call_time if min_time_less?(other) @max_call_time = other.max_call_time if other.max_call_time > max_call_time @total_call_time += other.total_call_time @total_exclusive_time += other.total_exclusive_time @sum_of_squares += other.sum_of_squares @call_count += other.call_count end self end |
#record_apdex(bucket, apdex_t) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/new_relic/agent/stats.rb', line 129 def record_apdex(bucket, apdex_t) case bucket when :apdex_s then @call_count += 1 when :apdex_t then @total_call_time += 1 when :apdex_f then @total_exclusive_time += 1 end if apdex_t @min_call_time = apdex_t @max_call_time = apdex_t else ::NewRelic::Agent.logger.warn("Attempted to set apdex_t to #{apdex_t.inspect}, backtrace = #{caller.join("\n")}") end end |
#record_data_point(value, exclusive_time = value) ⇒ Object Also known as: trace_call
record a single data point into the statistical gatherer. The gatherer will aggregate all data points collected over a specified period and upload its data to the NewRelic server
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/new_relic/agent/stats.rb', line 66 def record_data_point(value, exclusive_time = value) @call_count += 1 @total_call_time += value @min_call_time = value if value < @min_call_time || @call_count == 1 @max_call_time = value if value > @max_call_time @total_exclusive_time += exclusive_time @sum_of_squares += (value * value) self end |
#record_multiple_data_points(total_value, count = 1) ⇒ Object
Records multiple data points as one method call - this handles all the aggregation that would be done with multiple record_data_point calls
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/new_relic/agent/stats.rb', line 82 def record_multiple_data_points(total_value, count=1) return record_data_point(total_value) if count == 1 @call_count += count @total_call_time += total_value avg_val = total_value / count @min_call_time = avg_val if avg_val < @min_call_time || @call_count == count @max_call_time = avg_val if avg_val > @max_call_time @total_exclusive_time += total_value @sum_of_squares += (avg_val * avg_val) * count self end |
#reset ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/new_relic/agent/stats.rb', line 18 def reset @call_count = 0 @total_call_time = 0.0 @total_exclusive_time = 0.0 @min_call_time = 0.0 @max_call_time = 0.0 @sum_of_squares = 0.0 end |
#to_json(*_) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/new_relic/agent/stats.rb', line 52 def to_json(*_) { 'call_count' => call_count.to_i, 'min_call_time' => min_call_time.to_f, 'max_call_time' => max_call_time.to_f, 'total_call_time' => total_call_time.to_f, 'total_exclusive_time' => total_exclusive_time.to_f, 'sum_of_squares' => sum_of_squares.to_f }.to_json(*_) end |
#to_s ⇒ Object
48 49 50 |
# File 'lib/new_relic/agent/stats.rb', line 48 def to_s "[#{'%2i' % call_count.to_i} calls #{'%.4f' % total_call_time.to_f}s]" end |