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)

[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)

[Source]

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

cache_generate(event)

[Source]

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

cache_read(event)

[Source]

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

process_action(event)

[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:                 if log
    82:                         view_runtime = event.payload[:view_runtime]
    83:                         log.message("View rendering time: #{(view_runtime * 1000).to_i}") if view_runtime
    84:                 end
    85:         end

sql(event)

[Source]

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

[Validate]