Module: Statify
- Defined in:
- lib/statify.rb,
lib/statify/railtie.rb,
lib/statify/version.rb
Overview
Statify.configure do |config|
config.statsd = StatD.new...
end Statify.statsd =
Defined Under Namespace
Classes: Railtie
Constant Summary collapse
- VERSION =
"0.1.2"
Class Method Summary collapse
- .categories ⇒ Object
- .categories=(categories) ⇒ Object
- .configure {|_self| ... } ⇒ Object
- .statsd ⇒ Object
-
.statsd=(statsd) ⇒ Object
This takes an instance of a StatsD Statsd.new(‘127.1.1.1’, 8125).
- .subscribe ⇒ Object
Class Method Details
.categories ⇒ Object
36 37 38 |
# File 'lib/statify.rb', line 36 def self.categories @@categories end |
.categories=(categories) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/statify.rb', line 23 def self.categories=(categories) @@categories = categories # If you're running ruby-1.8.7 and your trying to get GC stats if @@categories.include?(:garbage_collection) if RUBY_VERSION < '1.9' # Fail and tell the user to remove the GC stats fail "The GC stats don't work in Ruby 1.8.7. Please remove the :grabage_collection from the categories" @@stats.delete(:grabage_collection) end end end |
.configure {|_self| ... } ⇒ Object
9 10 11 |
# File 'lib/statify.rb', line 9 def self.configure yield self end |
.statsd ⇒ Object
19 20 21 |
# File 'lib/statify.rb', line 19 def self.statsd @@statsd end |
.statsd=(statsd) ⇒ Object
This takes an instance of a StatsD Statsd.new(‘127.1.1.1’, 8125)
15 16 17 |
# File 'lib/statify.rb', line 15 def self.statsd=(statsd) @@statsd = statsd end |
.subscribe ⇒ Object
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/statify.rb', line 40 def self.subscribe if Statify.categories.include?(:sql) # This should give us reports on response times to queries ActiveSupport::Notifications.subscribe "sql.active_record" do |*args| event = ActiveSupport::Notifications::Event.new(*args) # Don't include explains or schema DB calls unless ["EXPLAIN", "SCHEMA"].include?(event.payload[:name]) # # We are hoping this gives us basic metris for query durations for us to track. @@statsd.timing "#{event.name}", event.duration end end end if Statify.categories.include?(:garbage_collection) || Statify.categories.include?(:controller) # This should give us reports on average response times by controller and action ActiveSupport::Notifications.subscribe "process_action.action_controller" do |*args| event = ActiveSupport::Notifications::Event.new(*args) if Statify.categories.include?(:garbage_collection) # Let's log the GC gc_stats = GC::stat @@statsd.count('gc_count', gc_stats[:count]) @@statsd.count('gc_heap_used', gc_stats[:heap_used]) @@statsd.count('gc_heap_length', gc_stats[:heap_length]) @@statsd.count('gc_heap_increment', gc_stats[:heap_increment]) @@statsd.count('gc_heap_live_num', gc_stats[:heap_live_num]) @@statsd.count('gc_heap_free_num', gc_stats[:heap_live_num]) @@statsd.count('gc_heap_final_num', gc_stats[:heap_live_num]) end if Statify.categories.include?(:controller) # Track overall, db and view durations @@statsd.timing "overall_duration|#{event.payload[:controller]}/#{event.payload[:action]}", event.duration @@statsd.timing "db_runtime|#{event.payload[:controller]}/#{event.payload[:action]}", event.payload[:db_runtime] @@statsd.timing "view_runtime|#{event.payload[:controller]}/#{event.payload[:action]}", event.payload[:view_runtime] end end end if Statify.categories.include?(:cache) # I want to keep track of how many cache hits we get as opposed to cache misses ActiveSupport::Notifications.subscribe "cache_fetch_hit.active_support" do |*args| event = ActiveSupport::Notifications::Event.new(*args) @@statsd.increment('cache_hit', 1) end # I want to keep track of how many cache misses we get as opposed to cache hits ActiveSupport::Notifications.subscribe "cache_write.active_support" do |*args| event = ActiveSupport::Notifications::Event.new(*args) @@statsd.increment('cache_miss', 1) end end end |