monitoring for the masses

55
Monitoring for the masses Rodrigo Fernandez HTML5DevConf 2015

Upload: rodrigo-fernandez

Post on 08-Jan-2017

613 views

Category:

Engineering


1 download

TRANSCRIPT

Page 1: Monitoring for the masses

Monitoring  for  the  masses  

Rodrigo  Fernandez  HTML5DevConf  2015  

Page 2: Monitoring for the masses

What  is  monitoring?  

Page 3: Monitoring for the masses

To  be  aware  of  the  state  of  a  system  and  observe  any  changes  

which  may  occur  over  Cme  

Page 4: Monitoring for the masses

Why  should  we  monitor?  

Page 5: Monitoring for the masses

Our  responsibility  shouldn’t  end  in  a  commit  

Page 6: Monitoring for the masses

Users  

Product  Owner  

Developer   System  Admin  

Code   Infrastructure  

Page 7: Monitoring for the masses

How  can  we  monitor?  

Page 8: Monitoring for the masses

Easy!  We  simply  instrument  our  applicaCon  and  stream  events  data  to  a  trending  system  for  

analysis,  correlaAon  and  anomaly  detecAon.  

Page 9: Monitoring for the masses

app  

server  

messenger  

tsdb  

analyAcs  

Page 10: Monitoring for the masses

InstrumentaCon  and  telemetry  

Page 11: Monitoring for the masses
Page 12: Monitoring for the masses

High  ResoluCon  Time  API  

Page 13: Monitoring for the masses

var Circle = function (radius) { ! if (radius <= 0) { ! throw new RangeError('Radius must be greater than zero!'); ! } ! this.radius = radius; !}; !!Circle.prototype.perimeter = function () { ! return 2 * Math.PI * this.radius; !}; !!Circle.prototype.area = function () { ! return Math.PI * Math.pow(this.radius, 2); !};  

Page 14: Monitoring for the masses

var start = Date.now(); !!var circle = new Circle(1); !circle.perimeter(); !circle.area(); !!Date.now() - start;  

Page 15: Monitoring for the masses

var start = Date.now(); !!var circle = new Circle(1); !circle.perimeter(); !circle.area(); !!Date.now() - start; // 0  

Page 16: Monitoring for the masses

var start = performance.now(); !!var circle = new Circle(1); !circle.perimeter(); !circle.area(); !!performance.now() - start;  

Page 17: Monitoring for the masses

var start = performance.now(); !!var circle = new Circle(1); !circle.perimeter(); !circle.area(); !!performance.now() - start; // 0.1449999999999818  

Page 18: Monitoring for the masses

-performance.now() + performance.now();  

Page 19: Monitoring for the masses

-performance.now() + performance.now(); // 0.009999999999990905  

Page 20: Monitoring for the masses
Page 21: Monitoring for the masses

NavigaCon  Cming  API  

Page 22: Monitoring for the masses
Page 23: Monitoring for the masses

performance.timing; !!{ ! "navigationStart": 1444712367243, ! "unloadEventStart": 0, ! "unloadEventEnd": 0, ! "redirectStart": 0, ! "redirectEnd": 0, ! "fetchStart": 1444712367504, ! "domainLookupStart": 1444712367507, ! "domainLookupEnd": 1444712367538, ! "connectStart": 1444712367538, ! "connectEnd": 1444712367616, ! "secureConnectionStart": 0, ! "requestStart": 1444712367616, ! "responseStart": 1444712367866, ! "responseEnd": 1444712367954, ! "domLoading": 1444712367867, ! "domInteractive": 1444712368966, ! "domContentLoadedEventStart": 1444712368966, ! "domContentLoadedEventEnd": 1444712369180, ! "domComplete": 1444712376251, ! "loadEventStart": 1444712376251, ! "loadEventEnd": 1444712376891 !}  

Page 24: Monitoring for the masses
Page 25: Monitoring for the masses

Resource  Cming  API  

Page 26: Monitoring for the masses

performance.getEntriesByType('resource'); !!{ ! "connectEnd": 0, ! "connectStart": 0, ! "domainLookupEnd": 0, ! "domainLookupStart": 0, ! "duration": 380.53100000252016, ! "entryType": "resource", ! "fetchStart": 661.7220000043744, ! "initiatorType": "link", ! "name": "https://lorem.ipsum.dolor/sit/amet.css", ! "redirectEnd": 0, ! "redirectStart": 0, ! "requestStart": 0, ! "responseEnd": 1042.2530000068946, ! "responseStart": 0, ! "secureConnectionStart": 0, ! "startTime": 661.7220000043744 !} !

Page 27: Monitoring for the masses
Page 28: Monitoring for the masses
Page 29: Monitoring for the masses
Page 30: Monitoring for the masses
Page 31: Monitoring for the masses

User  Cming  API  

Page 32: Monitoring for the masses

var circle = new Circle(1); !!performance.mark(’p:before'); !!circle.perimeter(); !!performance.mark(’p:after'); !!performance.measure(’p', ’p:before', ’p:after'); !!performance.getEntriesByType('measure');  

Page 33: Monitoring for the masses

{ ! "name": "p", ! "entryType": "measure", ! "startTime": 31442.615000000005, ! "duration": 0.09000000000014552 !}  

Page 34: Monitoring for the masses
Page 35: Monitoring for the masses

Beacon  API  

Page 36: Monitoring for the masses

window.addEventListener('unload', function () { !! var entries = performance.getEntries(); !! navigator.sendBeacon('/phone/home', JSON.stringify(entries)); !!});  

Page 37: Monitoring for the masses
Page 38: Monitoring for the masses

Polyfills  (modernizr.com)  

High  ResoluAon  Time   hVps://gist.github.com/paulirish/5438650  

NavigaAon  Timing   -­‐  

Resource  Timing   -­‐  

User  Timing   hVps://github.com/nicjansma/userCming.js  

Page  Visibility  hVps://github.com/ai/visibility.js  hVps://github.com/addyosmani/visibly.js  hVps://github.com/mathiasbynens/jquery-­‐visibility  

Beacon   hVps://github.com/miguelmota/Navigator.sendBeacon  

Page 39: Monitoring for the masses

Why  the  obsession  with  Amings  and  duraAons?  

Page 40: Monitoring for the masses

Doherty  &  Thadani  (1982)  

150  

200  

250  

300  

350  

400  

0.0   0.5   1.0   1.5   2.0   2.5   3.0  

Tran

sacAon

s  per  Hou

r  

System  Response  Time  (Seconds)  

Page 41: Monitoring for the masses

InstrumentaCon  with  AOP  

Page 42: Monitoring for the masses

var Circle = function (radius) { ! if (radius <= 0) { ! throw new RangeError('Radius must be greater than zero!'); ! } ! this.radius = radius; !}; !!Circle.prototype.perimeter = function () { ! return 2 * Math.PI * this.radius; !}; !!Circle.prototype.area = function () { ! return Math.PI * Math.pow(this.radius, 2); !};  

Page 43: Monitoring for the masses

meld.before(Circle.prototype, 'perimeter', function () { ! performance.mark('Circle.perimeter:before'); !}); !!meld.after(Circle.prototype, 'perimeter', function () { ! performance.mark('Circle.perimeter:after'); ! performance.measure('Circle.perimeter', 'Circle.perimeter:before', !'Circle.perimeter:after'); !});  

Page 44: Monitoring for the masses

var c1 = new Circle(1); !c1.perimeter(); !!var c2 = new Circle(2); !c2.perimeter(); !

Page 45: Monitoring for the masses

performance.getEntriesByName('Circle.perimeter'); !!![ ! { ! "name": "Circle.perimeter", ! "entryType": "measure", ! "startTime": 16.725, ! "duration": 0.11499999999999844 ! }, ! { ! "name": "Circle.perimeter", ! "entryType": "measure", ! "startTime": 16.89, ! "duration": 0.015000000000000568 ! } !] !

Page 46: Monitoring for the masses

InstrumentaCon  with  decorators  (ES2016)  

Page 47: Monitoring for the masses

let duration = function (target, name, descriptor) { ! let {value} = descriptor; ! let tag = `${target.constructor.name}.${name}`; ! let before = `${tag}:before`; ! let after = `${tag}:after`; !! descriptor.value = function(){ ! performance.mark(before); ! let result = value.call(this, ...arguments); ! performance.mark(after); ! performance.measure(tag, before, after); ! return result; ! }; !}; !

Page 48: Monitoring for the masses

class Circle { ! constructor(radius) { ! if (radius <= 0) { ! throw new RangeError('Radius must be greater than zero!'); ! } ! this.radius = radius; ! } !! @duration ! perimeter() { ! return 2 * Math.PI * this.radius; ! } !! @duration ! area() { ! return Math.PI * Math.pow(this.radius, 2); ! } !} !

Page 49: Monitoring for the masses

let c1 = new Circle(1); !let p1 = c1.perimeter(); !let a1 = c1.area(); !!!let c2 = new Circle(2); !let p2 = c2.perimeter(); !let a2 = c2.area(); !!!performance.getEntriesByType('measure'); !

Page 50: Monitoring for the masses

[ ! { ! "name": "Circle.perimeter", ! "entryType": "measure", ! "startTime": 8.280000000000001, ! "duration": 0.05999999999999872 ! }, ! { ! "name": "Circle.area", ! "entryType": "measure", ! "startTime": 8.360000000000001, ! "duration": 0.10499999999999865 ! }, ! { ! "name": "Circle.perimeter", ! "entryType": "measure", ! "startTime": 8.5, ! "duration": 0.015000000000000568 ! }, ! { ! "name": "Circle.area", ! "entryType": "measure", ! "startTime": 8.525, ! "duration": 0.005000000000000782 ! } !] !

Page 51: Monitoring for the masses

app  

server  

messenger  

tsdb  

analyAcs  

Page 52: Monitoring for the masses
Page 53: Monitoring for the masses
Page 54: Monitoring for the masses

Demo  

Page 55: Monitoring for the masses

Thank  you!  

github.com/rodfernandez