Class: CanvasStatsd::BlockStat
- Inherits:
-
Object
- Object
- CanvasStatsd::BlockStat
- Defined in:
- lib/canvas_statsd/block_stat.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#common_key ⇒ Object
Returns the value of attribute common_key.
-
#stats ⇒ Object
Returns the value of attribute stats.
Instance Method Summary collapse
- #exclusive_stats ⇒ Object
-
#initialize(common_key, statsd = CanvasStatsd::Statsd) ⇒ BlockStat
constructor
A new instance of BlockStat.
- #report ⇒ Object
- #subtract_exclusives(stats) ⇒ Object
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_key ⇒ Object
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 |
#stats ⇒ Object
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_stats ⇒ Object
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 |
#report ⇒ Object
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 |