SlideShare una empresa de Scribd logo
1 de 36
Descargar para leer sin conexión
A Node.JS Bag of Goodies for Analysing Web
                  Traffic

      Philip Tellis / philip@lognormal.com


                  ConFoo / 2012-03-02




        ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   1
Leave feeback on this talk at joind.in/5967

    ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   2
$ finger philip




       Philip Tellis
       philip@lognormal.com
       @bluesmoon
       geek - paranoid - speedfreak
       co-founder @ Log-Normal
       http://bluesmoon.info/




                  ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   3
Log-Normal




             We do real user web performance analysis




                ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   4
Log-Normal




   This talk covers some of the Node.JS modules we use to do this
                              analysis




                ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   5
Examples for this talk




         http://bluesmoon.github.com/talks/node-modules/




                ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   6
–
    Node.JS & npm



ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   7
0.1 The 2 minute Node.JS Tutorial


     node
     > m = require(’module’)
     > console.log(m.foo)

   We’ll be using node v0.6.x




                 ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   8
0.1 The 2 minute Node.JS Tutorial



     node script.js




              ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   9
0.1 The 2 minute Node.JS Tutorial



     echo "console.log(’hello, world!’)" | node

   Notice that in JavaScript, semicolons are optional




                 ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   10
0.2 Installing modules



     npm install module

   Installs into a local node_modules directory




                 ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   11
0.2 Installing modules globally



     sudo npm install -g module

   Installs into the /usr/lib/node_modules directory




                ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   12
0.2 npm help



    npm help npm




               ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   13
0.3 npmjs.org



                   search.npmjs.org




            ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   14
What’s the time?




                                     13:37?




               ConFoo / 2012-03-02    A Node.JS Bag of Goodies for Analysing Web Traffic   15
1
          HTTP Logs



ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   16
1.1 UserAgent Parsing


    npm install ua-parser

    var parser=require(’ua-parser’);
    var ua = parser.parse(ua_string);

    // family, major, minor, patch, os

  Extracted from Google’s BrowserScope Project




               ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   17
1.2 IP Addresses


    var net = require(’net’);

    net.isIP(ip);           // returns 0, 4 or 6

  The net module is part of node




               ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   18
1.3 GeoLocation


    npm install geoip-lite

    var geo = require(’geip-lite’);
    var loc = geo.lookup(ip);

    // country, region, city, ll

  Uses MaxMind’s GeoIP database. Very fast lookups, IPv4 & v6




               ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   19
1.3 geoip-lite’s hidden function


     var geo = require(’geip-lite’);
     geo.cmp(ip1, ip2);

     // -1, 0 or 1

   Used internally to do a binary search on the IP database




                 ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   20
1.4 Date formatting


     npm install prettydate

     var strftime = require(’prettydate’).strftime;

     var dstr = strftime(new Date, "%c");

   Also accepts a locale as a third parameter.




                 ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   21
1.5 Querystring Parsing


     var qs = require(’querystring’);

     qs.parse(’name=Larry&name=Moe&name=Curly’);
     // { name: [ ’Larry’, ’Moe’, ’Curly’ ] }




             ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   22
1.6 Creating Hashes


    var crypto = require(’crypto’);

    var hash = crypto.createHash(’sha1’);
    hash.update(data);

    var digest = hash.digest(’hex’);




             ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   23
1.6 Creating HMACs


    var crypto = require(’crypto’);

    var hmac = crypto.createHmac(’sha1’, key);
    hmac.update(data);

    var digest = hmac.digest(’base64’);




            ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   24
What’s the time?




                             It should be
                                 14:05
                                     I hope ;)




               ConFoo / 2012-03-02     A Node.JS Bag of Goodies for Analysing Web Traffic   25
2
Statistical Analysis



ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   26
2.1 faststats


     npm install fast-stats

     var Stats = require(’fast-stats’).Stats;
     var s = new Stats().push(1, 2, 3, 10, 8, 4, 3);
     console.log(s.amean().toFixed(2));

   Caveat: I haven’t pushed out a new version in a while




                 ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   27
2.2 gauss


    npm install gauss

    var gauss = require(’gauss’);
    var set = new gauss.Vector(5, 1, 3, 2, 21);
    console.log(set.mean());




            ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   28
2.3 statsd


    npm install statsd node-statsd

      github.com/etsy/statsd
      Easy to set up
      Requires graphite to plot charts
      Brought to you by Etsy




                ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   29
2.3 statsd



  var StatsD = require(’node-statsd’).StatsD
  c = new StatsD(’example.org’,8125)
  c.timing(’node_test.some_service.task.time’, 500)




             ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   30
2.4 cube


  Disclaimer: I’ve never used this one before

    npm install cube

      square.github.com/cube/
      github.com/square/cube/wiki




                ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   31
What’s the time?




                                     14:20?




               ConFoo / 2012-03-02    A Node.JS Bag of Goodies for Analysing Web Traffic   32
Help me out




   Still trying to figure out the best way to debug Node.JS memory
                      usage. Ideas? Let me know.




                ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   33
Questions?




ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   34
Leave feeback on this talk at joind.in/5967

    ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   35
Contact me



      Philip Tellis
      philip@lognormal.com
      @bluesmoon
      geek - paranoid - speedfreak
      co-founder @ Log-Normal
      http://bluesmoon.info/
      slideshare.net/bluesmoon
      joind.in/5967




                 ConFoo / 2012-03-02   A Node.JS Bag of Goodies for Analysing Web Traffic   36

Más contenido relacionado

La actualidad más candente

How%20to%20install%20PHP%20on%20Linux%20_%20laffers
How%20to%20install%20PHP%20on%20Linux%20_%20laffersHow%20to%20install%20PHP%20on%20Linux%20_%20laffers
How%20to%20install%20PHP%20on%20Linux%20_%20laffers
tutorialsruby
 

La actualidad más candente (20)

BPMS1
BPMS1BPMS1
BPMS1
 
ApacheCon 2014 - What's New in Apache httpd 2.4
ApacheCon 2014 - What's New in Apache httpd 2.4ApacheCon 2014 - What's New in Apache httpd 2.4
ApacheCon 2014 - What's New in Apache httpd 2.4
 
Websocket protocol overview
Websocket protocol overviewWebsocket protocol overview
Websocket protocol overview
 
Making the web faster
Making the web fasterMaking the web faster
Making the web faster
 
PageSpeed and SPDY
PageSpeed and SPDYPageSpeed and SPDY
PageSpeed and SPDY
 
Puppet Camp Berlin 2014 Closing Keynote: Next steps for doing more awesome th...
Puppet Camp Berlin 2014 Closing Keynote: Next steps for doing more awesome th...Puppet Camp Berlin 2014 Closing Keynote: Next steps for doing more awesome th...
Puppet Camp Berlin 2014 Closing Keynote: Next steps for doing more awesome th...
 
Npm scripts
Npm scriptsNpm scripts
Npm scripts
 
Mobile web performance - MoDev East
Mobile web performance - MoDev EastMobile web performance - MoDev East
Mobile web performance - MoDev East
 
How%20to%20install%20PHP%20on%20Linux%20_%20laffers
How%20to%20install%20PHP%20on%20Linux%20_%20laffersHow%20to%20install%20PHP%20on%20Linux%20_%20laffers
How%20to%20install%20PHP%20on%20Linux%20_%20laffers
 
HTTPS + Let's Encrypt
HTTPS + Let's EncryptHTTPS + Let's Encrypt
HTTPS + Let's Encrypt
 
Developing cacheable PHP applications - PHPLimburgBE 2018
Developing cacheable PHP applications - PHPLimburgBE 2018Developing cacheable PHP applications - PHPLimburgBE 2018
Developing cacheable PHP applications - PHPLimburgBE 2018
 
Ruby in the Browser - RubyConf 2011
Ruby in the Browser - RubyConf 2011Ruby in the Browser - RubyConf 2011
Ruby in the Browser - RubyConf 2011
 
cache concepts and varnish-cache
cache concepts and varnish-cachecache concepts and varnish-cache
cache concepts and varnish-cache
 
HTML5 WebSocket: The New Network Stack for the Web
HTML5 WebSocket: The New Network Stack for the WebHTML5 WebSocket: The New Network Stack for the Web
HTML5 WebSocket: The New Network Stack for the Web
 
Scalable talk notes
Scalable talk notesScalable talk notes
Scalable talk notes
 
How containers helped a SaaS startup be developed and go live
How containers helped a SaaS startup be developed and go liveHow containers helped a SaaS startup be developed and go live
How containers helped a SaaS startup be developed and go live
 
Resource registries plone conf 2014
Resource registries plone conf 2014Resource registries plone conf 2014
Resource registries plone conf 2014
 
Create a Varnish cluster in Kubernetes for Drupal caching - DrupalCon North A...
Create a Varnish cluster in Kubernetes for Drupal caching - DrupalCon North A...Create a Varnish cluster in Kubernetes for Drupal caching - DrupalCon North A...
Create a Varnish cluster in Kubernetes for Drupal caching - DrupalCon North A...
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with Ansible
 
Forget Grunt and Gulp! Webpack and NPM rule them all!
Forget Grunt and Gulp! Webpack and NPM rule them all!Forget Grunt and Gulp! Webpack and NPM rule them all!
Forget Grunt and Gulp! Webpack and NPM rule them all!
 

Similar a A Node.JS bag of goodies for analyzing Web Traffic

把鐵路開進視窗裡
把鐵路開進視窗裡把鐵路開進視窗裡
把鐵路開進視窗裡
Wei Jen Lu
 
1st Chinaonrails Open Course 高级战略
1st Chinaonrails Open Course 高级战略1st Chinaonrails Open Course 高级战略
1st Chinaonrails Open Course 高级战略
Jesse Cai
 
OSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js TutorialOSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js Tutorial
Tom Croucher
 

Similar a A Node.JS bag of goodies for analyzing Web Traffic (20)

Windows Azure Visual Studio "Monaco"", Because it’s mundane
Windows Azure Visual Studio "Monaco"", Because it’s mundaneWindows Azure Visual Studio "Monaco"", Because it’s mundane
Windows Azure Visual Studio "Monaco"", Because it’s mundane
 
把鐵路開進視窗裡
把鐵路開進視窗裡把鐵路開進視窗裡
把鐵路開進視窗裡
 
(C)NodeJS
(C)NodeJS(C)NodeJS
(C)NodeJS
 
MongoDB.local Austin 2018: MongoDB Ops Manager + Kubernetes
MongoDB.local Austin 2018: MongoDB Ops Manager + KubernetesMongoDB.local Austin 2018: MongoDB Ops Manager + Kubernetes
MongoDB.local Austin 2018: MongoDB Ops Manager + Kubernetes
 
CNCF Québec Meetup du 16 Novembre 2023
CNCF Québec Meetup du 16 Novembre 2023CNCF Québec Meetup du 16 Novembre 2023
CNCF Québec Meetup du 16 Novembre 2023
 
Node.js - A practical introduction (v2)
Node.js  - A practical introduction (v2)Node.js  - A practical introduction (v2)
Node.js - A practical introduction (v2)
 
introduction-infra-as-a-code using terraform
introduction-infra-as-a-code using terraformintroduction-infra-as-a-code using terraform
introduction-infra-as-a-code using terraform
 
1st Chinaonrails Open Course 高级战略
1st Chinaonrails Open Course 高级战略1st Chinaonrails Open Course 高级战略
1st Chinaonrails Open Course 高级战略
 
Happy porting x86 application to android
Happy porting x86 application to androidHappy porting x86 application to android
Happy porting x86 application to android
 
4 Node.js Gotchas: What your ops team needs to know
4 Node.js Gotchas: What your ops team needs to know4 Node.js Gotchas: What your ops team needs to know
4 Node.js Gotchas: What your ops team needs to know
 
OSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js TutorialOSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js Tutorial
 
Nodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredev
 
A Continuous Packaging Pipeline
A Continuous Packaging PipelineA Continuous Packaging Pipeline
A Continuous Packaging Pipeline
 
Instalação geo ip
Instalação geo ipInstalação geo ip
Instalação geo ip
 
Intro to Node.js
Intro to Node.jsIntro to Node.js
Intro to Node.js
 
No more Dockerfiles? Buildpacks to help you ship your image!
No more Dockerfiles? Buildpacks to help you ship your image!No more Dockerfiles? Buildpacks to help you ship your image!
No more Dockerfiles? Buildpacks to help you ship your image!
 
Digital RSE: automated code quality checks - RSE group meeting
Digital RSE: automated code quality checks - RSE group meetingDigital RSE: automated code quality checks - RSE group meeting
Digital RSE: automated code quality checks - RSE group meeting
 
maven-for-maine-jug-090226091601-phpapp02.ppt
maven-for-maine-jug-090226091601-phpapp02.pptmaven-for-maine-jug-090226091601-phpapp02.ppt
maven-for-maine-jug-090226091601-phpapp02.ppt
 
Can we run the Whole Web on Apache Sling?
Can we run the Whole Web on Apache Sling?Can we run the Whole Web on Apache Sling?
Can we run the Whole Web on Apache Sling?
 
Node js javascript no lado do servidor
Node js javascript no lado do servidorNode js javascript no lado do servidor
Node js javascript no lado do servidor
 

Más de Philip Tellis

Improving 3rd Party Script Performance With IFrames
Improving 3rd Party Script Performance With IFramesImproving 3rd Party Script Performance With IFrames
Improving 3rd Party Script Performance With IFrames
Philip Tellis
 
Analysing network characteristics with JavaScript
Analysing network characteristics with JavaScriptAnalysing network characteristics with JavaScript
Analysing network characteristics with JavaScript
Philip Tellis
 

Más de Philip Tellis (20)

Improving D3 Performance with CANVAS and other Hacks
Improving D3 Performance with CANVAS and other HacksImproving D3 Performance with CANVAS and other Hacks
Improving D3 Performance with CANVAS and other Hacks
 
Frontend Performance: Beginner to Expert to Crazy Person
Frontend Performance: Beginner to Expert to Crazy PersonFrontend Performance: Beginner to Expert to Crazy Person
Frontend Performance: Beginner to Expert to Crazy Person
 
Frontend Performance: De débutant à Expert à Fou Furieux
Frontend Performance: De débutant à Expert à Fou FurieuxFrontend Performance: De débutant à Expert à Fou Furieux
Frontend Performance: De débutant à Expert à Fou Furieux
 
Frontend Performance: Expert to Crazy Person
Frontend Performance: Expert to Crazy PersonFrontend Performance: Expert to Crazy Person
Frontend Performance: Expert to Crazy Person
 
Beyond Page Level Metrics
Beyond Page Level MetricsBeyond Page Level Metrics
Beyond Page Level Metrics
 
Frontend Performance: Beginner to Expert to Crazy Person (San Diego Web Perf ...
Frontend Performance: Beginner to Expert to Crazy Person (San Diego Web Perf ...Frontend Performance: Beginner to Expert to Crazy Person (San Diego Web Perf ...
Frontend Performance: Beginner to Expert to Crazy Person (San Diego Web Perf ...
 
Frontend Performance: Beginner to Expert to Crazy Person
Frontend Performance: Beginner to Expert to Crazy PersonFrontend Performance: Beginner to Expert to Crazy Person
Frontend Performance: Beginner to Expert to Crazy Person
 
Frontend Performance: Beginner to Expert to Crazy Person
Frontend Performance: Beginner to Expert to Crazy PersonFrontend Performance: Beginner to Expert to Crazy Person
Frontend Performance: Beginner to Expert to Crazy Person
 
Frontend Performance: Beginner to Expert to Crazy Person
Frontend Performance: Beginner to Expert to Crazy PersonFrontend Performance: Beginner to Expert to Crazy Person
Frontend Performance: Beginner to Expert to Crazy Person
 
mmm... beacons
mmm... beaconsmmm... beacons
mmm... beacons
 
RUM Distillation 101 -- Part I
RUM Distillation 101 -- Part IRUM Distillation 101 -- Part I
RUM Distillation 101 -- Part I
 
Improving 3rd Party Script Performance With IFrames
Improving 3rd Party Script Performance With IFramesImproving 3rd Party Script Performance With IFrames
Improving 3rd Party Script Performance With IFrames
 
Extending Boomerang
Extending BoomerangExtending Boomerang
Extending Boomerang
 
Abusing JavaScript to measure Web Performance, or, "how does boomerang work?"
Abusing JavaScript to measure Web Performance, or, "how does boomerang work?"Abusing JavaScript to measure Web Performance, or, "how does boomerang work?"
Abusing JavaScript to measure Web Performance, or, "how does boomerang work?"
 
The Statistics of Web Performance Analysis
The Statistics of Web Performance AnalysisThe Statistics of Web Performance Analysis
The Statistics of Web Performance Analysis
 
Abusing JavaScript to Measure Web Performance
Abusing JavaScript to Measure Web PerformanceAbusing JavaScript to Measure Web Performance
Abusing JavaScript to Measure Web Performance
 
Rum for Breakfast
Rum for BreakfastRum for Breakfast
Rum for Breakfast
 
Analysing network characteristics with JavaScript
Analysing network characteristics with JavaScriptAnalysing network characteristics with JavaScript
Analysing network characteristics with JavaScript
 
Input sanitization
Input sanitizationInput sanitization
Input sanitization
 
Messing with JavaScript and the DOM to measure network characteristics
Messing with JavaScript and the DOM to measure network characteristicsMessing with JavaScript and the DOM to measure network characteristics
Messing with JavaScript and the DOM to measure network characteristics
 

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 

A Node.JS bag of goodies for analyzing Web Traffic

  • 1. A Node.JS Bag of Goodies for Analysing Web Traffic Philip Tellis / philip@lognormal.com ConFoo / 2012-03-02 ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 1
  • 2. Leave feeback on this talk at joind.in/5967 ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 2
  • 3. $ finger philip Philip Tellis philip@lognormal.com @bluesmoon geek - paranoid - speedfreak co-founder @ Log-Normal http://bluesmoon.info/ ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 3
  • 4. Log-Normal We do real user web performance analysis ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 4
  • 5. Log-Normal This talk covers some of the Node.JS modules we use to do this analysis ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 5
  • 6. Examples for this talk http://bluesmoon.github.com/talks/node-modules/ ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 6
  • 7. Node.JS & npm ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 7
  • 8. 0.1 The 2 minute Node.JS Tutorial node > m = require(’module’) > console.log(m.foo) We’ll be using node v0.6.x ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 8
  • 9. 0.1 The 2 minute Node.JS Tutorial node script.js ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 9
  • 10. 0.1 The 2 minute Node.JS Tutorial echo "console.log(’hello, world!’)" | node Notice that in JavaScript, semicolons are optional ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 10
  • 11. 0.2 Installing modules npm install module Installs into a local node_modules directory ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 11
  • 12. 0.2 Installing modules globally sudo npm install -g module Installs into the /usr/lib/node_modules directory ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 12
  • 13. 0.2 npm help npm help npm ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 13
  • 14. 0.3 npmjs.org search.npmjs.org ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 14
  • 15. What’s the time? 13:37? ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 15
  • 16. 1 HTTP Logs ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 16
  • 17. 1.1 UserAgent Parsing npm install ua-parser var parser=require(’ua-parser’); var ua = parser.parse(ua_string); // family, major, minor, patch, os Extracted from Google’s BrowserScope Project ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 17
  • 18. 1.2 IP Addresses var net = require(’net’); net.isIP(ip); // returns 0, 4 or 6 The net module is part of node ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 18
  • 19. 1.3 GeoLocation npm install geoip-lite var geo = require(’geip-lite’); var loc = geo.lookup(ip); // country, region, city, ll Uses MaxMind’s GeoIP database. Very fast lookups, IPv4 & v6 ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 19
  • 20. 1.3 geoip-lite’s hidden function var geo = require(’geip-lite’); geo.cmp(ip1, ip2); // -1, 0 or 1 Used internally to do a binary search on the IP database ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 20
  • 21. 1.4 Date formatting npm install prettydate var strftime = require(’prettydate’).strftime; var dstr = strftime(new Date, "%c"); Also accepts a locale as a third parameter. ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 21
  • 22. 1.5 Querystring Parsing var qs = require(’querystring’); qs.parse(’name=Larry&name=Moe&name=Curly’); // { name: [ ’Larry’, ’Moe’, ’Curly’ ] } ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 22
  • 23. 1.6 Creating Hashes var crypto = require(’crypto’); var hash = crypto.createHash(’sha1’); hash.update(data); var digest = hash.digest(’hex’); ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 23
  • 24. 1.6 Creating HMACs var crypto = require(’crypto’); var hmac = crypto.createHmac(’sha1’, key); hmac.update(data); var digest = hmac.digest(’base64’); ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 24
  • 25. What’s the time? It should be 14:05 I hope ;) ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 25
  • 26. 2 Statistical Analysis ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 26
  • 27. 2.1 faststats npm install fast-stats var Stats = require(’fast-stats’).Stats; var s = new Stats().push(1, 2, 3, 10, 8, 4, 3); console.log(s.amean().toFixed(2)); Caveat: I haven’t pushed out a new version in a while ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 27
  • 28. 2.2 gauss npm install gauss var gauss = require(’gauss’); var set = new gauss.Vector(5, 1, 3, 2, 21); console.log(set.mean()); ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 28
  • 29. 2.3 statsd npm install statsd node-statsd github.com/etsy/statsd Easy to set up Requires graphite to plot charts Brought to you by Etsy ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 29
  • 30. 2.3 statsd var StatsD = require(’node-statsd’).StatsD c = new StatsD(’example.org’,8125) c.timing(’node_test.some_service.task.time’, 500) ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 30
  • 31. 2.4 cube Disclaimer: I’ve never used this one before npm install cube square.github.com/cube/ github.com/square/cube/wiki ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 31
  • 32. What’s the time? 14:20? ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 32
  • 33. Help me out Still trying to figure out the best way to debug Node.JS memory usage. Ideas? Let me know. ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 33
  • 34. Questions? ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 34
  • 35. Leave feeback on this talk at joind.in/5967 ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 35
  • 36. Contact me Philip Tellis philip@lognormal.com @bluesmoon geek - paranoid - speedfreak co-founder @ Log-Normal http://bluesmoon.info/ slideshare.net/bluesmoon joind.in/5967 ConFoo / 2012-03-02 A Node.JS Bag of Goodies for Analysing Web Traffic 36