garelic 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +60 -0
- data/Rakefile +2 -0
- data/garelic.gemspec +17 -0
- data/lib/garelic/dispatcher.rb +18 -0
- data/lib/garelic/version.rb +3 -0
- data/lib/garelic.rb +31 -0
- metadata +55 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Jan Suchal
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Garelic: Google Analytics Reports as "New Relic"-like performance monitoring for your Rails app
|
2
|
+
|
3
|
+
This is a proof of concept and will probably break things. Use it at your own risk.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
1. Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'garelic'
|
11
|
+
|
12
|
+
2. Add Garelic::Timing instrumentation to your GA code in application layout template like this:
|
13
|
+
|
14
|
+
<script type="text/javascript">
|
15
|
+
var _gaq = _gaq || [];
|
16
|
+
_gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
|
17
|
+
_gaq.push(['_setSiteSpeedSampleRate', 100]);
|
18
|
+
_gaq.push(['_trackPageview']);
|
19
|
+
|
20
|
+
<%= Garelic::Timing %>
|
21
|
+
|
22
|
+
(function() {
|
23
|
+
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
24
|
+
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
25
|
+
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
26
|
+
})();
|
27
|
+
</script>
|
28
|
+
|
29
|
+
3. Go to Google Analytics > Content > Site speed > User Timings
|
30
|
+
|
31
|
+
4. Enjoy!
|
32
|
+
|
33
|
+
|
34
|
+
## Know advantages
|
35
|
+
|
36
|
+
- it's free
|
37
|
+
- shows slow performing pages (not only actions)
|
38
|
+
- show response times histogram for any action (response time averages tend to lie, since distribution of response times is multimodal)
|
39
|
+
- segment/slice/dice response data across any dimensions available in your GA account
|
40
|
+
|
41
|
+
## Known drawbacks
|
42
|
+
|
43
|
+
- you can only track actions that return a response body (redirects, ajax-requests & async jobs are not supported)
|
44
|
+
- all timings are visible in page source code (if you are concerned about this look elsewere)
|
45
|
+
- caching GA code (e.g. page caching) & not modified response will probably break/skew reported statistics
|
46
|
+
- adding user timing table widgets to GA dashboards does not preserve sorting order (wtf?)
|
47
|
+
- it's kind of a hack
|
48
|
+
|
49
|
+
## TODO
|
50
|
+
|
51
|
+
- add more fine-grained ActiveRecord instrumentation
|
52
|
+
- add support for adding custom user tracers (e.g. for external services)
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
1. Fork it
|
57
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
58
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
59
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
60
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/garelic.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/garelic/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Jan Suchal"]
|
6
|
+
gem.email = ["johno@jsmf.net"]
|
7
|
+
gem.description = %q{Google Analytics Reports as "New Relic"-like performance monitoring for your Rails app}
|
8
|
+
gem.summary = %q{}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "garelic"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Garelic::VERSION
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module ActionController
|
2
|
+
class Metal < AbstractController::Base
|
3
|
+
alias :dispatch_without_garelic :dispatch
|
4
|
+
|
5
|
+
def dispatch(*args)
|
6
|
+
response = dispatch_without_garelic(*args)
|
7
|
+
|
8
|
+
timing_data = Garelic.build_user_timing_from_payload(Thread.current[:garelic_payload])
|
9
|
+
|
10
|
+
_, _, chunks = response
|
11
|
+
chunks.each do |chunk|
|
12
|
+
chunk.gsub!(Garelic::Timing, timing_data)
|
13
|
+
end
|
14
|
+
|
15
|
+
response
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/garelic.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require "garelic/version"
|
2
|
+
require "garelic/dispatcher"
|
3
|
+
|
4
|
+
class Garelic
|
5
|
+
Timing = '<!-- /* GARELIC DATA */ -->'.html_safe
|
6
|
+
|
7
|
+
def self.build_user_timing_from_payload(payload)
|
8
|
+
action_identifier = "#{payload[:controller]}##{payload[:action]}"
|
9
|
+
[
|
10
|
+
track_timing('Garelic', 'Response (Total)', payload[:total_runtime], action_identifier),
|
11
|
+
track_timing('Garelic', 'Response (Views)', payload[:view_runtime], action_identifier),
|
12
|
+
track_timing('Garelic', 'Response (ActiveRecord)', payload[:db_runtime], action_identifier),
|
13
|
+
].join("\n")
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.track_timing(category, variable, time, opt_label = nil, opt_sample = nil)
|
17
|
+
parameters = ["'#{category}'", "'#{variable}'", time.to_i]
|
18
|
+
parameters << "'#{opt_label}'" if opt_label
|
19
|
+
parameters << opt_sample if opt_sample
|
20
|
+
"_gaq.push(['_trackTiming', #{parameters.join(', ')}]);"
|
21
|
+
end
|
22
|
+
|
23
|
+
class Railtie < Rails::Railtie
|
24
|
+
initializer 'garelic.install_instrumentation' do
|
25
|
+
ActiveSupport::Notifications.subscribe('process_action.action_controller') do |_, start, finish, _, payload|
|
26
|
+
payload[:total_runtime] = (finish - start) * 1000
|
27
|
+
Thread.current[:garelic_payload] = payload
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: garelic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jan Suchal
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-02 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Google Analytics Reports as "New Relic"-like performance monitoring for
|
15
|
+
your Rails app
|
16
|
+
email:
|
17
|
+
- johno@jsmf.net
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- garelic.gemspec
|
28
|
+
- lib/garelic.rb
|
29
|
+
- lib/garelic/dispatcher.rb
|
30
|
+
- lib/garelic/version.rb
|
31
|
+
homepage: ''
|
32
|
+
licenses: []
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.8.23
|
52
|
+
signing_key:
|
53
|
+
specification_version: 3
|
54
|
+
summary: ''
|
55
|
+
test_files: []
|