Class
PhusionPassenger::Rails3Extensions::AnalyticsLogging

In: | lib/phusion_passenger/rails3_extensions/init.rb
Parent: | ActiveSupport::LogSubscriber

Methods

- cache_fetch_hit
- cache_generate
- cache_read
- install!
- process_action
- sql

Included Modules

- ACExtension
- ASBenchmarkableExtension

Classes and Modules
Module PhusionPassenger::Rails3Extensions::AnalyticsLogging::ACExtension
Module PhusionPassenger::Rails3Extensions::AnalyticsLogging::ASBenchmarkableExtension
Class PhusionPassenger::Rails3Extensions::AnalyticsLogging::ExceptionLogger
Public Class methods
install!(options)

[ show source ]

        # File lib/phusion_passenger/rails3_extensions/init.rb, line 41
    41:         def self.install!(options)
    42:                 analytics_logger = options["analytics_logger"]
    43:                 return false if !analytics_logger || !options["analytics"]
    44:
    45:                 # If the Ruby interpreter supports GC statistics then turn it on
    46:                 # so that the info can be logged.
    47:                 GC.enable_stats if GC.respond_to?(:enable_stats)
    48:
    49:                 subscriber = self.new
    50:                 AnalyticsLogging.attach_to(:action_controller, subscriber)
    51:                 AnalyticsLogging.attach_to(:active_record, subscriber)
    52:                 if defined?(ActiveSupport::Cache::Store)
    53:                         ActiveSupport::Cache::Store.instrument = true
    54:                         AnalyticsLogging.attach_to(:active_support, subscriber)
    55:                 end
    56:
    57:                 if defined?(ActionDispatch::ShowExceptions)
    58:                         Rails::Application.middleware.insert_after(
    59:                                 ActionDispatch::ShowExceptions,
    60:                                 ExceptionLogger, analytics_logger)
    61:                 end
    62:
    63:                 if defined?(ActionController::Base)
    64:                         ActionController::Base.class_eval do
    65:                                 include ACExtension
    66:                         end
    67:                 end
    68:
    69:                 if defined?(ActiveSupport::Benchmarkable)
    70:                         ActiveSupport::Benchmarkable.class_eval do
    71:                                 include ASBenchmarkableExtension
    72:                                 alias_method_chain :benchmark, :passenger
    73:                         end
    74:                 end
    75:
    76:                 return true
    77:         end

Public Instance methods
cache_fetch_hit(event)

[ show source ]

         # File lib/phusion_passenger/rails3_extensions/init.rb, line 103
    103:         def cache_fetch_hit(event)
    104:                 PhusionPassenger.log_cache_hit(nil, event.payload[:key])
    105:         end

cache_generate(event)

[ show source ]

         # File lib/phusion_passenger/rails3_extensions/init.rb, line 107
    107:         def cache_generate(event)
    108:                 PhusionPassenger.log_cache_miss(nil, event.payload[:key],
    109:                         event.duration * 1000)
    110:         end

cache_read(event)

[ show source ]

         # File lib/phusion_passenger/rails3_extensions/init.rb, line 95
     95:         def cache_read(event)
     96:                 if event.payload[:hit]
     97:                         PhusionPassenger.log_cache_hit(nil, event.payload[:key])
     98:                 else
     99:                         PhusionPassenger.log_cache_miss(nil, event.payload[:key])
    100:                 end
    101:         end

process_action(event)

[ show source ]

        # File lib/phusion_passenger/rails3_extensions/init.rb, line 79
    79:         def process_action(event)
    80:                 log = Thread.current[PASSENGER_ANALYTICS_WEB_LOG]
    81:                 log.message("View rendering time: #{(event.payload[:view_runtime] * 1000).to_i}") if log
    82:         end

sql(event)

[ show source ]

        # File lib/phusion_passenger/rails3_extensions/init.rb, line 84
    84:         def sql(event)
    85:                 log = Thread.current[PASSENGER_ANALYTICS_WEB_LOG]
    86:                 if log
    87:                         name = event.payload[:name]
    88:                         sql = event.payload[:sql]
    89:                         digest = Digest::MD5.hexdigest("#{name}\0#{sql}\0#{rand}")
    90:                         log.measured_time_points("DB BENCHMARK: #{digest}",
    91:                                 event.time, event.end, "#{name}\n#{sql}")
    92:                 end
    93:         end