Namespace

Statsd::Server

Public Class Methods

get_and_clear_stats!() click to toggle source
# File lib/statsd/server.rb, line 16
def self.get_and_clear_stats!
  counters = COUNTERS.dup
  timers = TIMERS.dup
  COUNTERS.clear
  TIMERS.clear
  [counters,timers]
end

Public Instance Methods

post_init() click to toggle source
# File lib/statsd/server.rb, line 12
def post_init
  puts "statsd server started!"
end
receive_data(msg) click to toggle source
# File lib/statsd/server.rb, line 24
def receive_data(msg)    
  msg.split("\n").each do |row|
    # puts row
    bits = row.split(':')
    key = bits.shift.gsub(/\s+/, '_').gsub(/\//, '-').gsub(/[^a-zA-Z_\-0-9\.]/, '')
    bits.each do |record|
      sample_rate = 1
      fields = record.split("|")    
      if (fields[1].strip == "ms") 
        TIMERS[key] ||= []
        TIMERS[key].push(fields[0].to_i)
      else
        if (fields[2] && fields[2].match(/^@([\d\.]+)/)) 
          sample_rate = fields[2].match(/^@([\d\.]+)/)[1]
        end
        COUNTERS[key] ||= 0
        COUNTERS[key] += (fields[0].to_i || 1) * (1.0 / sample_rate.to_f)
      end
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.