SlideShare a Scribd company logo
Garelic: Google
Analytics as App
Performance
Monitoring
@jsuchal (@rubyslava #21)
Features
Controller:
Average response times per action
Controller:
Most time spent per action
Controller:
Slowest pages
Controller:
Response times histogram
Controller:
Response times on timeline
ActiveRecord:
Average/most time spent per model
Deployments:
Average response times per deploy
and much more...
compare, segment,
slice & dice
Why?
● NewRelic is really great...but
   ○ "Database call response times"
     ■ Standard package = $24/month/server
   ○ "Transaction tracing"
     ■ Pro package = $149/month/server
   ○ basically unavailable for freelancers and small
     projects


● Proof-of-concept
   ○ 2 hours of hacking
   ○ 2 hours of waiting for Google Analytics
How?
● Google Analytics Site Speed User Timing
  _gaq.push([‘_trackTiming’, category, variable, time, opt_label, opt_sample]);



● Google Analytics Custom Variables
  _gaq.push([`_setCustomVar’, index, name, value, opt_scope]);



● ActiveSupport::Notifications
  ActiveSupport::Notifications.subscribe('process_action.action_controller') do |_, from, to, _, payload|
   Garelic::Metrics.report(:action, :db_runtime, payload[:db_runtime] || 0)
   Garelic::Metrics.report(:action, :view_runtime, payload[:view_runtime] || 0)
   Garelic::Metrics.report(:action, :total_runtime, (to - from) * 1000)
   Garelic::Metrics.action_identifier = "#{payload[:controller]}##{payload[:action]}"
  end

  ActiveSupport::Notifications.subscribe('sql.active_record') do |_, start, finish, _, payload|
   type = payload[:name] || 'Other SQL'
   Garelic::Metrics.report(:active_record, type, (finish - start) * 1000) if type != 'CACHE'
  end
How?
● Ruby Monkey Patching
  module ActionController
   class Metal < AbstractController::Base
    alias :dispatch_without_garelic :dispatch

    def dispatch(*args)
     Garelic::Metrics.reset!

      response = dispatch_without_garelic(*args)

      timing_data = Garelic.report_user_timing_from_metrics(Garelic::Metrics)

      _, _, chunks = response
      chunks.each do |chunk|
       chunk.gsub!(Garelic::Timing, timing_data)
      end

      response
    end
   end
  end
Limitations
● Cannot measure redirect, AJAX, async jobs

● Everything is visible in source code
   ○ Reporting stacktrace & raw SQL considered harmful


● Page caching breaks reports

● It's a hack & GA has its own limitations
Ideas for future development
● Tracking errors via GA events on error 500
  pages

● Tracking only slow responses (thresholding)

● Share Google Analytics dashboards &
  custom reports

● Pull requests welcome! https://github.
  com/jsuchal/garelic
Related resources


● All Presentation Software is Broken http://www.
   igvita.com/2012/05/14/all-presentation-software-is-broken/


● GA User Timing Method https://developers.google.
   com/analytics/devguides/collection/gajs/methods/gaJSApiUserTiming


● GA Custom Variables https://developers.google.
   com/analytics/devguides/collection/gajs/gaTrackingCustomVariables#setu
   p

More Related Content

ODP
Changing Etsy's Architectural Foundations with Continuous Deployment
PDF
Java2day 2013 : Modern workflows for javascript integration
PDF
Intro to sbt-web
PDF
Gits class #22: [ONLINE] Analyze Your User's Activities Using BigQuery and Da...
PDF
Front end microservices - October 2019
PPTX
intro to Angular js
PDF
Client Side Measurement & Performance With Rails
PPTX
Introduction to Serverless and Google Cloud Functions
Changing Etsy's Architectural Foundations with Continuous Deployment
Java2day 2013 : Modern workflows for javascript integration
Intro to sbt-web
Gits class #22: [ONLINE] Analyze Your User's Activities Using BigQuery and Da...
Front end microservices - October 2019
intro to Angular js
Client Side Measurement & Performance With Rails
Introduction to Serverless and Google Cloud Functions

Viewers also liked (6)

PDF
SQL: Query optimization in practice
PPT
Sql Server Performance Tuning
PPTX
Google Cloud Platform monitoring with Zabbix
PDF
Performance tuning and optimization (ppt)
PDF
Bias Driven Development - Mario Fusco - Codemotion Milan 2016
PDF
How to Apply Big Data Analytics and Machine Learning to Real Time Processing ...
SQL: Query optimization in practice
Sql Server Performance Tuning
Google Cloud Platform monitoring with Zabbix
Performance tuning and optimization (ppt)
Bias Driven Development - Mario Fusco - Codemotion Milan 2016
How to Apply Big Data Analytics and Machine Learning to Real Time Processing ...
Ad

Similar to Garelic: Google Analytics as App Performance monitoring (20)

PDF
Debugging Planning Issues Using Calcite's Built-in Loggers
PDF
Real World AngularJS recipes: beyond TodoMVC
PDF
Real World AngularJS recipes: beyond TodoMVC - Carlo Bonamico, Sonia Pini - C...
PDF
Sprint 68
PDF
PDF
PyGrunn2013 High Performance Web Applications with TurboGears
PPTX
Eko10 Workshop Opensource Database Auditing
KEY
improving the performance of Rails web Applications
PPTX
Eko10 workshop - OPEN SOURCE DATABASE MONITORING
PDF
Sprint 71
PDF
Gatling - Bordeaux JUG
PDF
AngularJS Workshop
PPTX
this-is-garbage-talk-2022.pptx
PDF
Droidcon Paris 2015
PDF
Automated Performance Testing
PDF
Web Traffic Time Series Forecasting
PDF
Sprint 44 review
PDF
Common Sense Agile
PPTX
Optimization and fault tolerance in distributed transaction with Node.JS Grap...
PDF
Most Advanced GTM Deployment. Ever!
Debugging Planning Issues Using Calcite's Built-in Loggers
Real World AngularJS recipes: beyond TodoMVC
Real World AngularJS recipes: beyond TodoMVC - Carlo Bonamico, Sonia Pini - C...
Sprint 68
PyGrunn2013 High Performance Web Applications with TurboGears
Eko10 Workshop Opensource Database Auditing
improving the performance of Rails web Applications
Eko10 workshop - OPEN SOURCE DATABASE MONITORING
Sprint 71
Gatling - Bordeaux JUG
AngularJS Workshop
this-is-garbage-talk-2022.pptx
Droidcon Paris 2015
Automated Performance Testing
Web Traffic Time Series Forecasting
Sprint 44 review
Common Sense Agile
Optimization and fault tolerance in distributed transaction with Node.JS Grap...
Most Advanced GTM Deployment. Ever!
Ad

More from Jano Suchal (20)

PDF
Slovensko.Digital: Čo ďalej?
PDF
Datanest 3.0
PDF
Improving code quality
PDF
Beyond search queries
PDF
Rank all the things!
PDF
Rank all the (geo) things!
PDF
Ako si vybrať programovácí jazyk alebo framework?
PPTX
Bonetics: Mastering Puppet Workshop
PPTX
Peter Mihalik: Puppet
PDF
Tomáš Čorej: Configuration management & CFEngine3
PDF
Ako si vybrať programovací jazyk a framework?
PDF
Miroslav Šimulčík: Temporálne databázy
PDF
Vojtech Rinik: Internship v USA - moje skúsenosti
PDF
Profiling and monitoring ruby & rails applications
PDF
Aký programovací jazyk a framework si vybrať a prečo?
PDF
Čo po GAMČI?
PDF
Petr Joachim: Redis na Super.cz
PDF
Metaprogramovanie #1
PDF
PostgreSQL: Advanced features in practice
PDF
elasticsearch - advanced features in practice
Slovensko.Digital: Čo ďalej?
Datanest 3.0
Improving code quality
Beyond search queries
Rank all the things!
Rank all the (geo) things!
Ako si vybrať programovácí jazyk alebo framework?
Bonetics: Mastering Puppet Workshop
Peter Mihalik: Puppet
Tomáš Čorej: Configuration management & CFEngine3
Ako si vybrať programovací jazyk a framework?
Miroslav Šimulčík: Temporálne databázy
Vojtech Rinik: Internship v USA - moje skúsenosti
Profiling and monitoring ruby & rails applications
Aký programovací jazyk a framework si vybrať a prečo?
Čo po GAMČI?
Petr Joachim: Redis na Super.cz
Metaprogramovanie #1
PostgreSQL: Advanced features in practice
elasticsearch - advanced features in practice

Recently uploaded (20)

PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Encapsulation theory and applications.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Electronic commerce courselecture one. Pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Approach and Philosophy of On baking technology
PDF
KodekX | Application Modernization Development
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Spectroscopy.pptx food analysis technology
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Spectral efficient network and resource selection model in 5G networks
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Encapsulation theory and applications.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Advanced methodologies resolving dimensionality complications for autism neur...
Electronic commerce courselecture one. Pdf
Encapsulation_ Review paper, used for researhc scholars
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Approach and Philosophy of On baking technology
KodekX | Application Modernization Development
sap open course for s4hana steps from ECC to s4
Per capita expenditure prediction using model stacking based on satellite ima...
Machine learning based COVID-19 study performance prediction
Digital-Transformation-Roadmap-for-Companies.pptx
Big Data Technologies - Introduction.pptx
Understanding_Digital_Forensics_Presentation.pptx
Spectroscopy.pptx food analysis technology

Garelic: Google Analytics as App Performance monitoring

  • 1. Garelic: Google Analytics as App Performance Monitoring @jsuchal (@rubyslava #21)
  • 10. and much more... compare, segment, slice & dice
  • 11. Why? ● NewRelic is really great...but ○ "Database call response times" ■ Standard package = $24/month/server ○ "Transaction tracing" ■ Pro package = $149/month/server ○ basically unavailable for freelancers and small projects ● Proof-of-concept ○ 2 hours of hacking ○ 2 hours of waiting for Google Analytics
  • 12. How? ● Google Analytics Site Speed User Timing _gaq.push([‘_trackTiming’, category, variable, time, opt_label, opt_sample]); ● Google Analytics Custom Variables _gaq.push([`_setCustomVar’, index, name, value, opt_scope]); ● ActiveSupport::Notifications ActiveSupport::Notifications.subscribe('process_action.action_controller') do |_, from, to, _, payload| Garelic::Metrics.report(:action, :db_runtime, payload[:db_runtime] || 0) Garelic::Metrics.report(:action, :view_runtime, payload[:view_runtime] || 0) Garelic::Metrics.report(:action, :total_runtime, (to - from) * 1000) Garelic::Metrics.action_identifier = "#{payload[:controller]}##{payload[:action]}" end ActiveSupport::Notifications.subscribe('sql.active_record') do |_, start, finish, _, payload| type = payload[:name] || 'Other SQL' Garelic::Metrics.report(:active_record, type, (finish - start) * 1000) if type != 'CACHE' end
  • 13. How? ● Ruby Monkey Patching module ActionController class Metal < AbstractController::Base alias :dispatch_without_garelic :dispatch def dispatch(*args) Garelic::Metrics.reset! response = dispatch_without_garelic(*args) timing_data = Garelic.report_user_timing_from_metrics(Garelic::Metrics) _, _, chunks = response chunks.each do |chunk| chunk.gsub!(Garelic::Timing, timing_data) end response end end end
  • 14. Limitations ● Cannot measure redirect, AJAX, async jobs ● Everything is visible in source code ○ Reporting stacktrace & raw SQL considered harmful ● Page caching breaks reports ● It's a hack & GA has its own limitations
  • 15. Ideas for future development ● Tracking errors via GA events on error 500 pages ● Tracking only slow responses (thresholding) ● Share Google Analytics dashboards & custom reports ● Pull requests welcome! https://github. com/jsuchal/garelic
  • 16. Related resources ● All Presentation Software is Broken http://www. igvita.com/2012/05/14/all-presentation-software-is-broken/ ● GA User Timing Method https://developers.google. com/analytics/devguides/collection/gajs/methods/gaJSApiUserTiming ● GA Custom Variables https://developers.google. com/analytics/devguides/collection/gajs/gaTrackingCustomVariables#setu p