Module: Statsd::Server
- Defined in:
- lib/statsd/server.rb
Overview
< EM::Connection
Defined Under Namespace
Classes: Daemon
Constant Summary collapse
- Version =
'0.5.4'
- FLUSH_INTERVAL =
10
- COUNTERS =
{}
- TIMERS =
{}
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
Instance Method Details
#post_init ⇒ Object
12 13 14 |
# File 'lib/statsd/server.rb', line 12 def post_init puts "statsd server started!" end |
#receive_data(msg) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# 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 |