class CanvasStatsd::Counter

Attributes

blocked_names[R]
key[R]

Public Class Methods

counters() click to toggle source
# File lib/canvas_statsd/counter.rb, line 4
def counters
  @counters ||= {}
end
new(key, blocked_names=[]) click to toggle source
# File lib/canvas_statsd/counter.rb, line 16
def initialize(key, blocked_names=[])
  @blocked_names = blocked_names
  @key = key
  @tls_key = "statsd.#{key}"
  self.class.register(self)
end
register(counter) click to toggle source
# File lib/canvas_statsd/counter.rb, line 8
def register(counter)
  counters[counter.key] = counter
end

Public Instance Methods

accepted_name?(name) click to toggle source
# File lib/canvas_statsd/counter.rb, line 39
def accepted_name?(name)
  !blocked_names.include?(name)
end
count() click to toggle source
# File lib/canvas_statsd/counter.rb, line 35
def count
  Thread.current[@tls_key]
end
finalize_count(cookie) click to toggle source
# File lib/canvas_statsd/counter.rb, line 31
def finalize_count(cookie)
  Thread.current[@tls_key] - cookie
end
start() click to toggle source
# File lib/canvas_statsd/counter.rb, line 23
def start
  Thread.current[@tls_key] ||= 0
end
track(name) click to toggle source
# File lib/canvas_statsd/counter.rb, line 27
def track(name)
  Thread.current[@tls_key] += 1 if Thread.current[@tls_key] && accepted_name?(name)
end