Class: CanvasStatsd::BlockStat

Inherits:
Object
  • Object
show all
Defined in:
lib/canvas_statsd/block_stat.rb

Direct Known Subclasses

RequestStat

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(common_key, statsd = CanvasStatsd::Statsd) ⇒ BlockStat

Returns a new instance of BlockStat.



7
8
9
10
11
# File 'lib/canvas_statsd/block_stat.rb', line 7

def initialize(common_key, statsd=CanvasStatsd::Statsd)
  self.common_key = common_key
  @statsd = statsd
  @stats = {}
end

Instance Attribute Details

#common_keyObject

Returns the value of attribute common_key.



5
6
7
# File 'lib/canvas_statsd/block_stat.rb', line 5

def common_key
  @common_key
end

#statsObject

Returns the value of attribute stats.



4
5
6
# File 'lib/canvas_statsd/block_stat.rb', line 4

def stats
  @stats
end

Instance Method Details

#exclusive_statsObject



21
22
23
24
# File 'lib/canvas_statsd/block_stat.rb', line 21

def exclusive_stats
  return nil unless @exclusives
  stats.map { |key, value| [key, value - (@exclusives[key] || 0.0)] }.to_h
end

#reportObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/canvas_statsd/block_stat.rb', line 26

def report
  if common_key
    stats.each do |(key, value)|
      @statsd.timing("#{common_key}.#{key}", value)
    end
    exclusive_stats&.each do |(key, value)|
      @statsd.timing("#{common_key}.exclusive.#{key}", value)
    end
  end
end

#subtract_exclusives(stats) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/canvas_statsd/block_stat.rb', line 13

def subtract_exclusives(stats)
  @exclusives ||= {}
  stats.each do |(key, value)|
    @exclusives[key] ||= 0.0
    @exclusives[key] += value
  end
end