Class: ScoutApm::ExternalServiceMetricStats

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/external_service_metric_stats.rb

Constant Summary collapse

DEFAULT_HISTOGRAM_SIZE =
50

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain_name, operation, scope, call_count, call_time) ⇒ ExternalServiceMetricStats

Returns a new instance of ExternalServiceMetricStats.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/scout_apm/external_service_metric_stats.rb', line 20

def initialize(domain_name, operation, scope, call_count, call_time)
  @domain_name = domain_name
  @operation = operation

  @call_count = call_count

  @call_time = call_time
  @min_call_time = call_time
  @max_call_time = call_time

  # This histogram is for call_time
  @histogram = NumericHistogram.new(DEFAULT_HISTOGRAM_SIZE)
  @histogram.add(call_time)

  @transaction_count = 0

  @scope = scope
end

Instance Attribute Details

#call_countObject (readonly)

Returns the value of attribute call_count.



12
13
14
# File 'lib/scout_apm/external_service_metric_stats.rb', line 12

def call_count
  @call_count
end

#call_timeObject (readonly)

Returns the value of attribute call_time.



13
14
15
# File 'lib/scout_apm/external_service_metric_stats.rb', line 13

def call_time
  @call_time
end

#domain_nameObject (readonly)

Returns the value of attribute domain_name.



6
7
8
# File 'lib/scout_apm/external_service_metric_stats.rb', line 6

def domain_name
  @domain_name
end

#histogramObject (readonly)

Returns the value of attribute histogram.



18
19
20
# File 'lib/scout_apm/external_service_metric_stats.rb', line 18

def histogram
  @histogram
end

#max_call_timeObject (readonly)

Returns the value of attribute max_call_time.



16
17
18
# File 'lib/scout_apm/external_service_metric_stats.rb', line 16

def max_call_time
  @max_call_time
end

#min_call_timeObject (readonly)

Returns the value of attribute min_call_time.



15
16
17
# File 'lib/scout_apm/external_service_metric_stats.rb', line 15

def min_call_time
  @min_call_time
end

#operationObject (readonly)

Returns the value of attribute operation.



7
8
9
# File 'lib/scout_apm/external_service_metric_stats.rb', line 7

def operation
  @operation
end

#scopeObject (readonly)

Returns the value of attribute scope.



8
9
10
# File 'lib/scout_apm/external_service_metric_stats.rb', line 8

def scope
  @scope
end

#transaction_countObject (readonly)

Returns the value of attribute transaction_count.



10
11
12
# File 'lib/scout_apm/external_service_metric_stats.rb', line 10

def transaction_count
  @transaction_count
end

Instance Method Details

#as_jsonObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/scout_apm/external_service_metric_stats.rb', line 59

def as_json
  json_attributes = [
    :domain_name,
    :operation,
    :scope,

    :transaction_count,
    :call_count,

    :histogram,
    :call_time,
    :max_call_time,
    :min_call_time,
  ]

  ScoutApm::AttributeArranger.call(self, json_attributes)
end

#combine!(other) ⇒ Object

Combine data from another ExternalServiceMetricStats into self. Modifies and returns self



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/scout_apm/external_service_metric_stats.rb', line 45

def combine!(other)
  return self if other == self

  @transaction_count += other.transaction_count
  @call_count += other.call_count
  @call_time += other.call_time

  @min_call_time = other.min_call_time if @min_call_time.zero? or other.min_call_time < @min_call_time
  @max_call_time = other.max_call_time if other.max_call_time > @max_call_time

  @histogram.combine!(other.histogram)
  self
end

#increment_transaction_count!Object

Called by the Set on each ExternalServiceMetricStats object that it holds, only once during the recording of a transaction.

Don’t call elsewhere, and don’t set to 1 in the initializer.



81
82
83
# File 'lib/scout_apm/external_service_metric_stats.rb', line 81

def increment_transaction_count!
  @transaction_count += 1
end

#keyObject

Merge data in this scope. Used in ExternalServiceMetricSet



40
41
42
# File 'lib/scout_apm/external_service_metric_stats.rb', line 40

def key
  @key ||= [domain_name, operation, scope]
end