fed-perf-logger
v0.3.2
Published
Server meant to log performance data reported from the browser
Downloads
5
Maintainers
Readme
#fed-perf-logger
Will open a connection on port 8888 to log performance data to.
##Installation
npm install -g fed-perf-logger
from our private registry.
##Usage
###Server
fed-perf-logger
from any location. The forever
project can be used to keep the service up as a daemon.
USAGE: fed-perf-logger [OPTIONS]
Options:
-h, --help Show help [boolean]
-p, --port [default: 8888]
-e, --elasticsearch [default: "localhost:9200"]
###Client
Here is a sample script to log perforamnce data to fed-perf-logger
:
(function(){
var req = new XMLHttpRequest();
req.open('POST', 'SERVER URL/perf-log');
req.send(
JSON.stringify(
['navigationStart','redirectStart','unloadStart','unloadEnd','redirectEnd','fetchStart','domainLookupStart','domainLookupEnd','connectStart','secureConnectionStart','connectEnd','requestStart','responseStart','unloadEventStart','unloadEventEnd','responseEnd','domLoading','domInteractive','domContentLoadedEventStart','domContentLoaded','domContentLoadedEventEnd','domComplete','loadEventStart','loadEventEnd']
.reduce(function(prev, curr){
prev[curr]=performance.timing[curr];
if(prev[curr] !== null && prev[curr] !== undefined){
prev[curr] = prev[curr] === 0 ? 0 : prev[curr] - performance.timing.navigationStart;
}
return prev;
}, {type: 'performance.timing', url: location.href})
)
);
})();
Or to log XHR data:
(function(){
var oldSend = XMLHttpRequest.prototype.send;
var PERF_LOG_URL = 'SERVER URL/perf-log';
XMLHttpRequest.prototype.send = function(){
var oldStateChange = this.onreadystatechange || function(){};
this.requestStart = Date.now();
this.onreadystatechange = function(){
if(this.readyState === XMLHttpRequest.prototype.DONE){
this.requestEnd = Date.now();
}
oldStateChange.apply(this, arguments);
if(this.readyState === XMLHttpRequest.prototype.DONE){
this.handleEnd = Date.now();
if(this.requestURL !== PERF_LOG_URL){
var req = new XMLHttpRequest();
var that = this;
req.open('POST', PERF_LOG_URL);
req.send(JSON.stringify([
'requestStart', 'requestEnd', 'handleEnd'
].reduce(function(prev, curr){
prev[curr] = that[curr] - that.requestStart;
return prev;
}, {
status: this.status,
responseURL: this.responseURL,
statusText: this.statusText
}))
);
}
}
};
oldSend.apply(this, arguments);
};
})();