Class: Statsd::Graphite
- Inherits:
-
EM::Connection
- Object
- EM::Connection
- Statsd::Graphite
- Defined in:
- lib/statsd/graphite.rb
Instance Attribute Summary collapse
-
#counters ⇒ Object
Returns the value of attribute counters.
-
#flush_interval ⇒ Object
Returns the value of attribute flush_interval.
-
#timers ⇒ Object
Returns the value of attribute timers.
Instance Method Summary collapse
Instance Attribute Details
#counters ⇒ Object
Returns the value of attribute counters.
7 8 9 |
# File 'lib/statsd/graphite.rb', line 7 def counters @counters end |
#flush_interval ⇒ Object
Returns the value of attribute flush_interval.
7 8 9 |
# File 'lib/statsd/graphite.rb', line 7 def flush_interval @flush_interval end |
#timers ⇒ Object
Returns the value of attribute timers.
7 8 9 |
# File 'lib/statsd/graphite.rb', line 7 def timers @timers end |
Instance Method Details
#flush_stats ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/statsd/graphite.rb', line 9 def flush_stats puts "#{Time.now} Flushing #{counters.count} counters and #{timers.count} timers to Graphite." stat_string = '' ts = Time.now.to_i num_stats = 0 # store counters counters.each_pair do |key,value| = "#{key} #{value} #{ts}\n" stat_string += counters[key] = 0 num_stats += 1 end # store timers timers.each_pair do |key, values| if (values.length > 0) pct_threshold = 90 values.sort! count = values.count min = values.first max = values.last mean = min max_at_threshold = max if (count > 1) # average all the timing data sum = values.inject( 0 ) { |s,x| s+x } mean = sum / values.count # strip off the top 100-threshold threshold_index = (((100 - pct_threshold) / 100.0) * count).round values = values[0..-threshold_index] max_at_threshold = values.last end = "" += "#{key}.mean #{mean} #{ts}\n" += "#{key}.upper #{max} #{ts}\n" += "#{key}.upper_#{pct_threshold} #{max_at_threshold} #{ts}\n" += "#{key}.lower #{min} #{ts}\n" += "#{key}.count #{count} #{ts}\n" stat_string += timers[key] = [] num_stats += 1 end end stat_string += "statsd.numStats #{num_stats} #{ts}\n" # send to graphite send_data stat_string close_connection_after_writing end |