Class: PhusionPassenger::Rails3Extensions::AnalyticsLogging

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Defined in:
lib/phusion_passenger/rails3_extensions/init.rb

Defined Under Namespace

Modules: ACExtension, ASBenchmarkableExtension Classes: ExceptionLogger

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.install!(options) ⇒ Object



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
# File 'lib/phusion_passenger/rails3_extensions/init.rb', line 41

def self.install!(options)
	analytics_logger = options["analytics_logger"]
	return false if !analytics_logger || !options["analytics"]
	
	# If the Ruby interpreter supports GC statistics then turn it on
	# so that the info can be logged.
	GC.enable_stats if GC.respond_to?(:enable_stats)
	
	subscriber = self.new
	AnalyticsLogging.attach_to(:action_controller, subscriber)
	AnalyticsLogging.attach_to(:active_record, subscriber)
	if defined?(ActiveSupport::Cache::Store)
		ActiveSupport::Cache::Store.instrument = true
		AnalyticsLogging.attach_to(:active_support, subscriber)
	end
	
	if defined?(ActionDispatch::ShowExceptions)
		Rails.application.middleware.insert_after(
			ActionDispatch::ShowExceptions,
			ExceptionLogger, analytics_logger)
	end
	
	if defined?(ActionController::Base)
		ActionController::Base.class_eval do
			include ACExtension
		end
	end
	
	if defined?(ActiveSupport::Benchmarkable)
		ActiveSupport::Benchmarkable.class_eval do
			include ASBenchmarkableExtension
			alias_method_chain :benchmark, :passenger
		end
	end
	
	return true
end

Instance Method Details

#cache_fetch_hit(event) ⇒ Object



106
107
108
# File 'lib/phusion_passenger/rails3_extensions/init.rb', line 106

def cache_fetch_hit(event)
	PhusionPassenger.log_cache_hit(nil, event.payload[:key])
end

#cache_generate(event) ⇒ Object



110
111
112
113
# File 'lib/phusion_passenger/rails3_extensions/init.rb', line 110

def cache_generate(event)
	PhusionPassenger.log_cache_miss(nil, event.payload[:key],
		event.duration * 1000)
end

#cache_read(event) ⇒ Object



98
99
100
101
102
103
104
# File 'lib/phusion_passenger/rails3_extensions/init.rb', line 98

def cache_read(event)
	if event.payload[:hit]
		PhusionPassenger.log_cache_hit(nil, event.payload[:key])
	else
		PhusionPassenger.log_cache_miss(nil, event.payload[:key])
	end
end

#process_action(event) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/phusion_passenger/rails3_extensions/init.rb', line 79

def process_action(event)
	log = Thread.current[PASSENGER_ANALYTICS_WEB_LOG]
	if log
		view_runtime = event.payload[:view_runtime]
		log.message("View rendering time: #{(view_runtime * 1000).to_i}") if view_runtime
	end
end

#sql(event) ⇒ Object



87
88
89
90
91
92
93
94
95
96
# File 'lib/phusion_passenger/rails3_extensions/init.rb', line 87

def sql(event)
	log = Thread.current[PASSENGER_ANALYTICS_WEB_LOG]
	if log
		name = event.payload[:name]
		sql = event.payload[:sql]
		digest = Digest::MD5.hexdigest("#{name}\0#{sql}\0#{rand}")
		log.measured_time_points("DB BENCHMARK: #{digest}",
			event.time, event.end, "#{name}\n#{sql}")
	end
end