Class: Garelic
- Inherits:
-
Object
show all
- Defined in:
- lib/garelic.rb,
lib/garelic/version.rb
Defined Under Namespace
Classes: Metrics, Middleware, Railtie
Constant Summary
collapse
- Timing =
'<!-- /* GARELIC DATA */ -->'.html_safe
- VERSION =
"0.2.0"
- @@deployed_version_slot =
5
Class Method Summary
collapse
Class Method Details
.monitoring(profile_id) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/garelic.rb', line 11
def self.monitoring(profile_id)
buffer = "<script type=\"text/javascript\">\nvar _gaq = _gaq || [];\n_gaq.push(['_setAccount', '\#{profile_id}']);\n_gaq.push(['_setSiteSpeedSampleRate', 100]);\n\#{report_deployed_version}\n_gaq.push(['_trackPageview']);\n\n\#{Garelic::Timing}\n\n(function() {\nvar ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\nga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\nvar s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\n})();\n</script>\n"
buffer.html_safe
end
|
.report_deployed_version ⇒ Object
32
33
34
|
# File 'lib/garelic.rb', line 32
def self.report_deployed_version
"_gaq.push(['_setCustomVar', #{deployed_version_slot}, 'Garelic (Deployed version)', '#{deployed_version}', 3])" unless deployed_version.blank?
end
|
.report_user_timing_for_action(metrics, action_identifier) ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/garelic.rb', line 43
def self.report_user_timing_for_action(metrics, action_identifier)
[
track_timing('Garelic (Controller)', 'Response time (Total)', metrics[:total_runtime], action_identifier),
track_timing('Garelic (Controller)', 'Response time (Views)', metrics[:view_runtime], action_identifier),
track_timing('Garelic (Controller)', 'Response time (ActiveRecord)', metrics[:db_runtime], action_identifier),
]
end
|
.report_user_timing_for_active_record(metrics, action_identifier) ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/garelic.rb', line 51
def self.report_user_timing_for_active_record(metrics, action_identifier)
timings = []
metrics.each do |call_type, time|
timings << track_timing('Garelic (ActiveRecord)', call_type, time, action_identifier)
end
timings
end
|
.report_user_timing_from_metrics(metrics) ⇒ Object
36
37
38
39
40
41
|
# File 'lib/garelic.rb', line 36
def self.report_user_timing_from_metrics(metrics)
reports = report_user_timing_for_action(metrics[:action], metrics.action_identifier)
reports += report_user_timing_for_active_record(metrics[:active_record], metrics.action_identifier)
reports.join("\n")
end
|
.track_timing(category, variable, time, opt_label = nil, opt_sample = nil) ⇒ Object
59
60
61
62
63
64
|
# File 'lib/garelic.rb', line 59
def self.track_timing(category, variable, time, opt_label = nil, opt_sample = nil)
parameters = ["'#{category}'", "'#{variable}'", time.to_i]
parameters << "'#{opt_label}'" if opt_label
parameters << opt_sample if opt_sample
"_gaq.push(['_trackTiming', #{parameters.join(', ')}]);"
end
|