Giter Site home page Giter Site logo

garelic's Introduction

Garelic: Use Google Analytics as "New Relic" performance monitoring for your Rails app

This gem uses Google Analytics User Timing API to report application performance statistics directly to Google Analytics, where you can slice & dice your data as you wish.

Here are some features with pictures:

Or look at these slides from a Garelic presentation.

Installation

It's easy as 1-2-3.

Step 1. Add this line to your application's Gemfile:

gem 'garelic'

Step 2. Add <%= Garelic.monitoring 'UA-XXXXXX-X' %> instrumentation in application layout template (before the closing </head> tag) like this:

<head>
    <!-- other rails stuff -->
    <%= Garelic.monitoring 'UA-XXXXXX-X' %>
    <!-- make sure you remove your old GA code! -->
</head>

Step 3. Go to Google Analytics > Content > Site Speed > User Timings

Enjoy!

Known advantages

  • it's free
  • shows slow performing pages (not only actions)
  • show response times histogram for any action (response time averages tend to lie, since distribution of response times is multimodal)
  • segment/slice/dice response data across any dimensions available in your GA account

Known drawbacks

  • you can only track actions that return a response body (redirects, ajax-requests & async jobs are not supported)
  • all timings are visible in page source code (if you are concerned about this look elsewere)
  • caching GA code (e.g. page caching) & not modified response will probably break/skew reported statistics
  • adding user timing table widgets to GA dashboards does not preserve sorting order (wtf?)
  • it's kind of a hack

TODO

  • add support for adding custom user tracers (e.g. for external services)

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

garelic's People

Contributors

jsuchal avatar martinliptak avatar

Stargazers

Andrew Johnson avatar Luiz Eduardo de Oliveira Fonseca avatar Max F. Findel avatar Muescha avatar Angus H. avatar Jian Ma avatar Hady Mahmoud avatar Ben Lee-Cohen avatar Patrik Bóna avatar Song Liu avatar Andy K. avatar placeless avatar Florian LAMACHE avatar Alex Le avatar debbbbie avatar  avatar Theo Li avatar Ricardo do Valle avatar Mourad De Clerck avatar sparkrico avatar Haibin Yu avatar Kai avatar Youssef Shahin avatar Rodrigo Tassinari de Oliveira avatar Rafael Souza avatar Rafael Barbolo avatar  avatar Steven Yue avatar ivanfoong avatar Samuel Molnár avatar  avatar aIex quiterio avatar Marble Wu avatar Lukas Platinsky avatar Joel Van Horn avatar Andrew Briening avatar Grant Walker avatar Steve Hoeksema avatar Govinda Fichtner avatar closer avatar Christian Nennemann avatar Jun Lin avatar Wen-Tien Chang avatar Patrick Veverka avatar  avatar  avatar Andy Si avatar Edditoria avatar jjy avatar Pavol Zbell avatar Robin Hwang avatar David Collom avatar Albert Pak avatar SeHoon Park avatar  avatar Ivan Nudzik avatar Vipin avatar  avatar lauren avatar Zubair Shams avatar James Xian avatar Tony Han avatar Kris avatar Prasanth Jayachandran avatar  avatar Denys Slipetskyy avatar Ondrej Galbavy avatar Yury Koleda avatar Gael Gillard avatar Kevin Tham avatar Heesang Chae avatar Amol Pujari avatar Ajmal Afif avatar Matt Hayes avatar Lucas Crivellari Macieira avatar ldng avatar Malachai avatar Greg Reinacker avatar David Montesdeoca avatar Ben D'Angelo avatar Surya Tripathi avatar Dan Dimerman avatar Lyle Underwood avatar Yoshinori Hirasawa avatar tom quas avatar Edy Laverde avatar Davy Peter Braun avatar Chris Le (TRIODE) avatar RT avatar Pablo avatar Pietro Di Bello avatar Andrew Havens avatar zach zhao avatar  avatar Andy Davies avatar Adam Okoń avatar Dr. Simon Harrer avatar Tom-Eric Gerritsen avatar Rajesh Koilpillai avatar Victor Stan avatar

Watchers

Pritesh avatar Scott Coleman avatar  avatar Petr Halas avatar Lam Thai avatar Nihad Abbasov avatar Luiz Eduardo de Oliveira Fonseca avatar James Cloos avatar Eric avatar  avatar Pavol Zbell avatar Ricardo do Valle avatar Peter Truchan avatar  avatar

garelic's Issues

Garelic is not loading in production

I installed the gem and it works in development but not in production.

Somehow it doesn't load Garelic in production.

Started GET "/" for 76.10.173.74 at 2012-10-05 00:58:21 -0400
Processing by PagesController#main as HTML
Rendered shared/_streaming-engine.html.erb (3.0ms)
Read fragment views/ruby_mine (0.1ms)
Rendered shared/_mine.html.erb (0.3ms)
Rendered pages/main.html.erb within layouts/application (3.9ms)
Rendered layouts/_google_analytics.html.erb (2.5ms)
Rendered shared/_header.html.erb (4.1ms)
Completed 500 Internal Server Error in 677ms

ActionView::Template::Error (uninitialized constant ActionView::CompiledTemplates::Garelic):
5: _gaq.push(['_setSiteSpeedSampleRate', 100]);
6: _gaq.push(['_trackPageview']);
7:
8: <%= Garelic::Timing %>
9:
10: (function() {
11: var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
app/views/layouts/_google_analytics.html.erb:8:in _app_views_layouts__google_analytics_html_erb__777870273_82504730' app/views/shared/_header.html.erb:31:in_app_views_shared__header_html_erb___819031644_82606250'
app/views/layouts/application.html.erb:3:in `_app_views_layouts_application_html_erb__178177862_83895200'

<!-- /* GARELIC DATA */ --> was not gsub

ruby 2.0
rails 3.2.12

also with newrelic_rpm 3.5.8.72 enable enduser

<script type="text/javascript">
          var _gaq = _gaq || [];
          _gaq.push(['_setAccount', 'UA-xxxxx-x]);
          _gaq.push(['_setSiteSpeedSampleRate', 100]);

          _gaq.push(['_trackPageview']);

          <!-- /* GARELIC DATA */ -->

          (function() {
              var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
              ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
              var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
          })();
      </script>

NoMethodError: undefined method `[]' for nil:NilClass: SHOW client_min_messages

rails s
WARNING: Nokogiri was built against LibXML version 2.7.8, but has dynamically loaded 2.8.0
=> Booting WEBrick
=> Rails 3.2.8 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-10-20 14:03:25] INFO WEBrick 1.3.1
[2012-10-20 14:03:25] INFO ruby 1.9.3 (2011-10-30) [i686-linux]
[2012-10-20 14:03:25] INFO WEBrick::HTTPServer#start: pid=4908 port=3000

Started GET "/items" for 127.0.0.1 at 2012-10-20 14:03:56 +0800
NoMethodError: undefined method []' for nil:NilClass: SHOW client_min_messages NoMethodError: undefined method[]' for nil:NilClass: SET client_min_messages TO ''
NoMethodError: undefined method []' for nil:NilClass: SHOW client_min_messages NoMethodError: undefined method[]' for nil:NilClass: SET client_min_messages TO ''

ActiveRecord::StatementInvalid (NoMethodError: undefined method []' for nil:NilClass: SET client_min_messages TO ''): garelic (0.1.1) lib/garelic.rb:70:inreport'
garelic (0.1.1) lib/garelic.rb:50:in block (2 levels) in <class:Railtie>' activesupport (3.2.8) lib/active_support/notifications/fanout.rb:47:incall'
activesupport (3.2.8) lib/active_support/notifications/fanout.rb:47:in publish' activesupport (3.2.8) lib/active_support/notifications/fanout.rb:25:inblock in publish'
activesupport (3.2.8) lib/active_support/notifications/fanout.rb:25:in each' activesupport (3.2.8) lib/active_support/notifications/fanout.rb:25:inpublish'
activesupport (3.2.8) lib/active_support/notifications/instrumenter.rb:25:in ensure in instrument' activesupport (3.2.8) lib/active_support/notifications/instrumenter.rb:25:ininstrument'
activerecord (3.2.8) lib/active_record/connection_adapters/abstract_adapter.rb:275:in log' activerecord (3.2.8) lib/active_record/connection_adapters/postgresql_adapter.rb:653:inexecute'
activerecord (3.2.8) lib/active_record/connection_adapters/postgresql_adapter.rb:906:in client_min_messages=' activerecord (3.2.8) lib/active_record/connection_adapters/postgresql_adapter.rb:391:inensure in set_standard_conforming_strings'
activerecord (3.2.8) lib/active_record/connection_adapters/postgresql_adapter.rb:391:in set_standard_conforming_strings' activerecord (3.2.8) lib/active_record/connection_adapters/postgresql_adapter.rb:1233:inconfigure_connection'
activerecord (3.2.8) lib/active_record/connection_adapters/postgresql_adapter.rb:1220:in connect' activerecord (3.2.8) lib/active_record/connection_adapters/postgresql_adapter.rb:329:ininitialize'
activerecord (3.2.8) lib/active_record/connection_adapters/postgresql_adapter.rb:28:in new' activerecord (3.2.8) lib/active_record/connection_adapters/postgresql_adapter.rb:28:inpostgresql_connection'
activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:309:in new_connection' activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:319:incheckout_new_connection'
activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:241:in block (2 levels) in checkout' activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:236:inloop'
activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:236:in block in checkout' /usr/local/rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/monitor.rb:211:inmon_synchronize'
activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:233:in checkout' activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:96:inblock in connection'
/usr/local/rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/monitor.rb:211:in mon_synchronize' activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:95:inconnection'
activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:404:in retrieve_connection' activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_specification.rb:170:inretrieve_connection'
activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_specification.rb:144:in connection' activerecord (3.2.8) lib/active_record/query_cache.rb:67:inrescue in call'
activerecord (3.2.8) lib/active_record/query_cache.rb:61:in call' activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:473:incall'
actionpack (3.2.8) lib/action_dispatch/middleware/callbacks.rb:28:in block in call' activesupport (3.2.8) lib/active_support/callbacks.rb:405:in_run__437639331__call__178485851__callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in __run_callback' activesupport (3.2.8) lib/active_support/callbacks.rb:385:in_run_call_callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:81:in run_callbacks' actionpack (3.2.8) lib/action_dispatch/middleware/callbacks.rb:27:incall'
actionpack (3.2.8) lib/action_dispatch/middleware/reloader.rb:65:in call' actionpack (3.2.8) lib/action_dispatch/middleware/remote_ip.rb:31:incall'
actionpack (3.2.8) lib/action_dispatch/middleware/debug_exceptions.rb:16:in call' actionpack (3.2.8) lib/action_dispatch/middleware/show_exceptions.rb:56:incall'
railties (3.2.8) lib/rails/rack/logger.rb:26:in call_app' railties (3.2.8) lib/rails/rack/logger.rb:16:incall'
actionpack (3.2.8) lib/action_dispatch/middleware/request_id.rb:22:in call' rack (1.4.1) lib/rack/methodoverride.rb:21:incall'
rack (1.4.1) lib/rack/runtime.rb:17:in call' activesupport (3.2.8) lib/active_support/cache/strategy/local_cache.rb:72:incall'
rack (1.4.1) lib/rack/lock.rb:15:in call' actionpack (3.2.8) lib/action_dispatch/middleware/static.rb:62:incall'
railties (3.2.8) lib/rails/engine.rb:479:in call' railties (3.2.8) lib/rails/application.rb:223:incall'
rack (1.4.1) lib/rack/content_length.rb:14:in call' railties (3.2.8) lib/rails/rack/log_tailer.rb:17:incall'
rack (1.4.1) lib/rack/handler/webrick.rb:59:in service' /usr/local/rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:138:inservice'
/usr/local/rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:94:in run' /usr/local/rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/server.rb:191:inblock in start_thread'

Rendered /usr/local/rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/_trace.erb (2.2ms)
Rendered /usr/local/rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (5.9ms)
Rendered /usr/local/rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (23.1ms)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.