module CanvasStatsd::Statsd
Public Class Methods
append_hostname?()
click to toggle source
# File lib/canvas_statsd/statsd.rb, line 111 def self.append_hostname? @append_hostname end
batch() { || ... }
click to toggle source
# File lib/canvas_statsd/statsd.rb, line 80 def self.batch return yield unless (old_instance = instance) old_instance.batch do |batch| Thread.current[:canvas_statsd] = batch yield end ensure Thread.current[:canvas_statsd] = old_instance end
escape(str, replacement = '_')
click to toggle source
replace “.” in key names with another character to avoid creating spurious sub-folders in graphite
# File lib/canvas_statsd/statsd.rb, line 41 def self.escape(str, replacement = '_') str.respond_to?(:gsub)? str.gsub('.', replacement) : str end
hostname()
click to toggle source
# File lib/canvas_statsd/statsd.rb, line 45 def self.hostname @hostname ||= Socket.gethostname.split(".").first end
instance()
click to toggle source
# File lib/canvas_statsd/statsd.rb, line 90 def self.instance thread_statsd = Thread.current[:canvas_statsd] return thread_statsd if thread_statsd if !defined?(@statsd) statsd_settings = CanvasStatsd.settings if statsd_settings && statsd_settings[:host] @statsd = ::Statsd.new(statsd_settings[:host]) @statsd.port = statsd_settings[:port] if statsd_settings[:port] @statsd.namespace = statsd_settings[:namespace] if statsd_settings[:namespace] @statsd.batch_size = statsd_settings[:batch_size] if statsd_settings.key?(:batch_size) @statsd.batch_byte_size = statsd_settings[:batch_byte_size] if statsd_settings.key?(:batch_byte_size) @append_hostname = !statsd_settings.key?(:append_hostname) || !!statsd_settings[:append_hostname] else @statsd = nil end end @statsd end
reset_instance()
click to toggle source
# File lib/canvas_statsd/statsd.rb, line 115 def self.reset_instance remove_instance_variable(:@statsd) if defined?(@statsd) Thread.current[:canvas_statsd] = nil end
time(stat, sample_rate=1) { || ... }
click to toggle source
# File lib/canvas_statsd/statsd.rb, line 73 def self.time(stat, sample_rate=1) start = Time.now result = yield self.timing(stat, ((Time.now - start) * 1000).round, sample_rate) result end