Skip to content

Commit

Permalink
Fixes quasor#2, alters usage of round() to support Ruby 1.8.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgibbins committed May 21, 2012
1 parent ca10606 commit 49d1225
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lib/statsd/graphite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
module Statsd
class Graphite < EM::Connection
attr_accessor :counters, :timers, :flush_interval

def initialize(*args)
puts args
super
# stuff here...
end

def post_init
# puts counters.size
# send_data 'Hello'
Expand All @@ -18,21 +18,21 @@ def post_init
end

def receive_data(data)
p data
p data
end

# def unbind
# p ' connection totally closed'
# EventMachine::stop_event_loop
# end

def flush_stats
print "#{Time.now} Flushing #{counters.count} counters and #{timers.count} timers to Graphite."
stat_string = ''
time = ::Benchmark.realtime do
ts = Time.now.to_i
num_stats = 0
num_stats = 0

# store counters
counters.each_pair do |key,value|
message = "stats.#{key} #{value} #{ts}\n"
Expand All @@ -41,10 +41,10 @@ def flush_stats

num_stats += 1
end

# store timers
timers.each_pair do |key, values|
if (values.length > 0)
if (values.length > 0)
pct_threshold = 90
values.sort!
count = values.count
Expand Down Expand Up @@ -74,16 +74,16 @@ def flush_stats
stat_string += message

timers[key] = []

num_stats += 1
end
end
stat_string += "statsd.numStats #{num_stats} #{ts}\n"
end

end
# send to graphite
send_data stat_string
puts "complete. (#{time.round(3)}s)"
puts "complete. (#{(time*100).round()/100.0}s)"
close_connection_after_writing
end
end
Expand Down

0 comments on commit 49d1225

Please sign in to comment.