Class: NewRelic::Agent::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/new_relic/agent/stats.rb

Direct Known Subclasses

SqlTrace

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStats

Returns a new instance of Stats.



11
12
13
# File 'lib/new_relic/agent/stats.rb', line 11

def initialize
  reset
end

Instance Attribute Details

#call_countObject Also known as: apdex_s

Returns the value of attribute call_count.



4
5
6
# File 'lib/new_relic/agent/stats.rb', line 4

def call_count
  @call_count
end

#max_call_timeObject

Returns the value of attribute max_call_time.



6
7
8
# File 'lib/new_relic/agent/stats.rb', line 6

def max_call_time
  @max_call_time
end

#min_call_timeObject

Returns the value of attribute min_call_time.



5
6
7
# File 'lib/new_relic/agent/stats.rb', line 5

def min_call_time
  @min_call_time
end

#sum_of_squaresObject

Returns the value of attribute sum_of_squares.



9
10
11
# File 'lib/new_relic/agent/stats.rb', line 9

def sum_of_squares
  @sum_of_squares
end

#total_call_timeObject Also known as: apdex_t

Returns the value of attribute total_call_time.



7
8
9
# File 'lib/new_relic/agent/stats.rb', line 7

def total_call_time
  @total_call_time
end

#total_exclusive_timeObject Also known as: apdex_f

Returns the value of attribute total_exclusive_time.



8
9
10
# File 'lib/new_relic/agent/stats.rb', line 8

def total_exclusive_time
  @total_exclusive_time
end

Instance Method Details

#==(other) ⇒ Object



100
101
102
103
104
105
106
107
108
109
# File 'lib/new_relic/agent/stats.rb', line 100

def ==(other)
  (
    @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



92
93
94
# File 'lib/new_relic/agent/stats.rb', line 92

def increment_count(value = 1)
  @call_count += value
end

#inspectObject



96
97
98
# File 'lib/new_relic/agent/stats.rb', line 96

def inspect
  "#<NewRelic::Agent::Stats #{to_s} >"
end

#is_reset?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/new_relic/agent/stats.rb', line 24

def is_reset?
  call_count == 0 && total_call_time == 0.0 && total_exclusive_time == 0.0
end

#merge(other_stats) ⇒ Object



28
29
30
31
# File 'lib/new_relic/agent/stats.rb', line 28

def merge(other_stats)
  stats = self.clone
  stats.merge!(other_stats)
end

#merge!(other_stats) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/new_relic/agent/stats.rb', line 33

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_fObject



124
125
126
# File 'lib/new_relic/agent/stats.rb', line 124

def record_apdex_f
  @total_exclusive_time += 1
end

#record_apdex_sObject



116
117
118
# File 'lib/new_relic/agent/stats.rb', line 116

def record_apdex_s
  @call_count += 1
end

#record_apdex_tObject



120
121
122
# File 'lib/new_relic/agent/stats.rb', line 120

def record_apdex_t
  @total_call_time += 1
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



63
64
65
66
67
68
69
70
71
72
# File 'lib/new_relic/agent/stats.rb', line 63

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



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/new_relic/agent/stats.rb', line 79

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

#resetObject



15
16
17
18
19
20
21
22
# File 'lib/new_relic/agent/stats.rb', line 15

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



49
50
51
52
53
54
55
56
57
58
# File 'lib/new_relic/agent/stats.rb', line 49

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_sObject



45
46
47
# File 'lib/new_relic/agent/stats.rb', line 45

def to_s
  "[#{'%2i' % call_count.to_i} calls #{'%.4f' % total_call_time.to_f}s]"
end