Class: ScoutApm::MetricMeta

Inherits:
Object
  • Object
show all
Includes:
BucketNameSplitter
Defined in:
lib/scout_apm/metric_meta.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BucketNameSplitter

#bucket, #key, #name

Constructor Details

#initialize(metric_name, options = {}) ⇒ MetricMeta

Returns a new instance of MetricMeta.



6
7
8
9
10
11
12
# File 'lib/scout_apm/metric_meta.rb', line 6

def initialize(metric_name, options = {})
  @metric_name = metric_name
  @metric_id = nil
  @scope = options[:scope]
  @desc = options[:desc]
  @extra = {}
end

Instance Attribute Details

#client_idObject

Returns the value of attribute client_id.



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

def client_id
  @client_id
end

#descObject

Returns the value of attribute desc.



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

def desc
  @desc
end

#extraObject

Returns the value of attribute extra.



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

def extra
  @extra
end

#metric_idObject

Returns the value of attribute metric_id.



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

def metric_id
  @metric_id
end

#metric_nameObject

Returns the value of attribute metric_name.



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

def metric_name
  @metric_name
end

#scopeObject

Returns the value of attribute scope.



14
15
16
# File 'lib/scout_apm/metric_meta.rb', line 14

def scope
  @scope
end

Class Method Details

.key_metric?(metric_name) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/scout_apm/metric_meta.rb', line 28

def self.key_metric?(metric_name)
  !!(metric_name =~ /\A(Controller|Job)\//)
end

Instance Method Details

#==(o) ⇒ Object



37
38
39
# File 'lib/scout_apm/metric_meta.rb', line 37

def ==(o)
  self.eql?(o)
end

#as_jsonObject



56
57
58
59
60
# File 'lib/scout_apm/metric_meta.rb', line 56

def as_json
  json_attributes = [:bucket, :name, :desc, :extra, [:scope, :scope_hash]]
  # query, stack_trace
  ScoutApm::AttributeArranger.call(self, json_attributes)
end

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
54
# File 'lib/scout_apm/metric_meta.rb', line 48

def eql?(o)
 self.class             == o.class                &&
   metric_name.downcase == o.metric_name.downcase &&
   scope                == o.scope                &&
   client_id            == o.client_id            &&
   desc                 == o.desc
end

#hashObject



41
42
43
44
45
46
# File 'lib/scout_apm/metric_meta.rb', line 41

def hash
  h = metric_name.downcase.hash
  h ^= scope.downcase.hash unless scope.nil?
  h ^= desc.downcase.hash unless desc.nil?
  h
end

#key_metric?Boolean

A key metric is the “core” of a request - either the Rails controller reached, or the background Job executed

Returns:

  • (Boolean)


24
25
26
# File 'lib/scout_apm/metric_meta.rb', line 24

def key_metric?
  self.class.key_metric?(metric_name)
end

#to_json(*a) ⇒ Object

To avoid conflicts with different JSON libaries



33
34
35
# File 'lib/scout_apm/metric_meta.rb', line 33

def to_json(*a)
   %Q[{"metric_id":#{metric_id || 'null'},"metric_name":#{metric_name.to_json},"scope":#{scope.to_json || 'null'}}]
end

#typeObject

Unsure if type or bucket is a better name.



19
20
21
# File 'lib/scout_apm/metric_meta.rb', line 19

def type
  bucket
end