Class: InstStatsd::Counter
- Inherits:
-
Object
- Object
- InstStatsd::Counter
- Defined in:
- lib/inst_statsd/counter.rb
Instance Attribute Summary collapse
-
#blocked_names ⇒ Object
readonly
Returns the value of attribute blocked_names.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Class Method Summary collapse
Instance Method Summary collapse
- #accepted_name?(name) ⇒ Boolean
- #count ⇒ Object
- #finalize_count(cookie) ⇒ Object
-
#initialize(key, blocked_names = [], tags: {}, short_stat: nil) ⇒ Counter
constructor
A new instance of Counter.
- #start ⇒ Object
- #track(name) ⇒ Object
Constructor Details
#initialize(key, blocked_names = [], tags: {}, short_stat: nil) ⇒ Counter
Returns a new instance of Counter.
17 18 19 20 21 22 |
# File 'lib/inst_statsd/counter.rb', line 17 def initialize(key, blocked_names = [], tags: {}, short_stat: nil) @blocked_names = blocked_names @key = key @tls_key = "statsd.#{key}" self.class.register(self) end |
Instance Attribute Details
#blocked_names ⇒ Object (readonly)
Returns the value of attribute blocked_names.
15 16 17 |
# File 'lib/inst_statsd/counter.rb', line 15 def blocked_names @blocked_names end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
15 16 17 |
# File 'lib/inst_statsd/counter.rb', line 15 def key @key end |
Class Method Details
.counters ⇒ Object
6 7 8 |
# File 'lib/inst_statsd/counter.rb', line 6 def counters @counters ||= {} end |
.register(counter) ⇒ Object
10 11 12 |
# File 'lib/inst_statsd/counter.rb', line 10 def register(counter) counters[counter.key] = counter end |
Instance Method Details
#accepted_name?(name) ⇒ Boolean
40 41 42 |
# File 'lib/inst_statsd/counter.rb', line 40 def accepted_name?(name) !blocked_names.include?(name) end |
#count ⇒ Object
36 37 38 |
# File 'lib/inst_statsd/counter.rb', line 36 def count Thread.current[@tls_key] end |
#finalize_count(cookie) ⇒ Object
32 33 34 |
# File 'lib/inst_statsd/counter.rb', line 32 def finalize_count() Thread.current[@tls_key] - end |
#start ⇒ Object
24 25 26 |
# File 'lib/inst_statsd/counter.rb', line 24 def start Thread.current[@tls_key] ||= 0 end |
#track(name) ⇒ Object
28 29 30 |
# File 'lib/inst_statsd/counter.rb', line 28 def track(name) Thread.current[@tls_key] += 1 if Thread.current[@tls_key] && accepted_name?(name) end |