Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed event for incoming request. #290

Merged
merged 1 commit into from Jan 8, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 26 additions & 37 deletions lib/network.js
Expand Up @@ -11,25 +11,25 @@ module.exports.Monitor = internals.NetworkMonitor = function (server) {
this._responseTimes = {};
this._server = server;

this._server.ext('onRequest', this._onRequest.bind(this));
this._server.on('request-internal', this._onRequest.bind(this));
this._server.on('response', this._onResponse.bind(this));
};


internals.NetworkMonitor.prototype._onRequest = function (request, reply) {
internals.NetworkMonitor.prototype._onRequest = function (request, event, tags) {

var self = this;
var port = request.connection.info.port;

this._requests[port] = this._requests[port] || { total: 0, disconnects: 0, statusCodes: {} };
this._requests[port].total++;
if (tags.received) {
this._requests[port] = this._requests[port] || { total: 0, disconnects: 0, statusCodes: {} };
this._requests[port].total++;

request.once('disconnect', function () {
request.once('disconnect', function () {

self._requests[port].disconnects++;
});

return reply.continue();
self._requests[port].disconnects++;
});
}
};


Expand Down Expand Up @@ -64,11 +64,7 @@ internals.NetworkMonitor.prototype.reset = function () {

internals.NetworkMonitor.prototype.requests = function (callback) {

var self = this;
process.nextTick(function() {

callback(null, self._requests);
});
callback(null, this._requests);
};


Expand Down Expand Up @@ -96,36 +92,29 @@ internals.NetworkMonitor.prototype.concurrents = function (callback) {

internals.NetworkMonitor.prototype.responseTimes = function (callback) {

var self = this;

process.nextTick(function () {

var ports = Object.keys(self._responseTimes);
var overview = {};
for (var i = 0, il = ports.length; i < il; ++i) {
var port = ports[i];
var count = Hoek.reach(self, '_responseTimes.' + port + '.count', { default: 1});
overview[port] = {
avg: self._responseTimes[port].total / count,
max: self._responseTimes[port].max
};
}
var ports = Object.keys(this._responseTimes);
var overview = {};
for (var i = 0, il = ports.length; i < il; ++i) {
var port = ports[i];
var count = Hoek.reach(this, '_responseTimes.' + port + '.count', { default: 1});
overview[port] = {
avg: this._responseTimes[port].total / count,
max: this._responseTimes[port].max
};
}

return callback(null, overview);
});
return callback(null, overview);
};


internals.NetworkMonitor.prototype.sockets = function (httpAgents, httpsAgents, callback) {

process.nextTick(function() {

var result = {
http: internals.getSocketCount(httpAgents),
https: internals.getSocketCount(httpsAgents)
};
callback(null, result);
});
var result = {
http: internals.getSocketCount(httpAgents),
https: internals.getSocketCount(httpsAgents)
};
callback(null, result);
};


Expand Down