Class: InstStatsd::BlockStat
- Inherits:
-
Object
- Object
- InstStatsd::BlockStat
- Defined in:
- lib/inst_statsd/block_stat.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#common_key ⇒ Object
Returns the value of attribute common_key.
-
#short_stat ⇒ Object
Returns the value of attribute short_stat.
-
#stats ⇒ Object
Returns the value of attribute stats.
-
#tags ⇒ Object
Returns the value of attribute tags.
Instance Method Summary collapse
- #exclusive_stats ⇒ Object
-
#initialize(common_key, statsd = InstStatsd::Statsd, tags: {}, short_stat: nil) ⇒ BlockStat
constructor
A new instance of BlockStat.
- #report ⇒ Object
- #subtract_exclusives(stats) ⇒ Object
Constructor Details
#initialize(common_key, statsd = InstStatsd::Statsd, tags: {}, short_stat: nil) ⇒ BlockStat
Returns a new instance of BlockStat.
7 8 9 10 11 12 13 14 |
# File 'lib/inst_statsd/block_stat.rb', line 7 def initialize(common_key, statsd = InstStatsd::Statsd, tags: {}, short_stat: nil) self.common_key = common_key @tags = @short_stat = short_stat @short_stat ||= common_key @statsd = statsd @stats = {} end |
Instance Attribute Details
#common_key ⇒ Object
Returns the value of attribute common_key.
5 6 7 |
# File 'lib/inst_statsd/block_stat.rb', line 5 def common_key @common_key end |
#short_stat ⇒ Object
Returns the value of attribute short_stat.
5 6 7 |
# File 'lib/inst_statsd/block_stat.rb', line 5 def short_stat @short_stat end |
#stats ⇒ Object
Returns the value of attribute stats.
5 6 7 |
# File 'lib/inst_statsd/block_stat.rb', line 5 def stats @stats end |
#tags ⇒ Object
Returns the value of attribute tags.
5 6 7 |
# File 'lib/inst_statsd/block_stat.rb', line 5 def @tags end |
Instance Method Details
#exclusive_stats ⇒ Object
24 25 26 27 28 |
# File 'lib/inst_statsd/block_stat.rb', line 24 def exclusive_stats return nil unless @exclusives stats.to_h { |key, value| [key, value - (@exclusives[key] || 0.0)] } end |
#report ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/inst_statsd/block_stat.rb', line 30 def report return unless common_key stats.each do |(key, value)| @statsd.timing("#{common_key}.#{key}", value, tags: @tags, short_stat: "#{@short_stat}.#{key}") end exclusive_stats&.each do |(key, value)| @statsd.timing("#{common_key}.exclusive.#{key}", value, tags: @tags, short_stat: "#{@short_stat}.exclusive.#{key}") end end |
#subtract_exclusives(stats) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/inst_statsd/block_stat.rb', line 16 def subtract_exclusives(stats) @exclusives ||= {} stats.each do |(key, value)| @exclusives[key] ||= 0.0 @exclusives[key] += value end end |