diff --git a/lib/httpServerAgent.js b/lib/httpServerAgent.js index 1fffea3..b091170 100644 --- a/lib/httpServerAgent.js +++ b/lib/httpServerAgent.js @@ -20,6 +20,10 @@ var https = require('https') var cluster = require('cluster') var domain = require('domain') +// constants +var FINISH_EVENT_NAME = 'finish' +var ABRUPT_CLOSE_EVENT_NAME = 'close' + module.exports = function httpServerAgent () { var SpmAgent = require('spm-agent') var Agent = SpmAgent.Agent @@ -37,20 +41,18 @@ module.exports = function httpServerAgent () { timer: timer, stats: stats, logger: logger, - histogram: histogram, - FINISH_EVENT_NAME: 'finish', - ABRUPT_CLOSE_EVENT_NAME: 'close' + histogram: histogram } // bind monitorHttp safely - safeProcess(ctx, monitorHttp) + var monitor = safeProcess(ctx, monitorHttp) // setup monitoring agent var hAgent = new Agent({ start: function (agent) { this._agent = agent - patchHttpServer(monitorHttp) - patchHttpsServer(monitorHttp) + patchHttpServer(monitor) + patchHttpsServer(monitor) var timerId = setInterval(function () { var httpStats = stats.toJSON() var responseTimes = histogram.toJSON() @@ -61,8 +63,8 @@ module.exports = function httpServerAgent () { httpStats['3xxRate'] ? httpStats['3xxRate'].count : 0, // http.3xx (int) httpStats['4xxRate'] ? httpStats['4xxRate'].count : 0, // http.4xx (int) httpStats['5xxRate'] ? httpStats['5xxRate'].count : 0, // http.5xx (int) - reqSize, - resSize, + ctx.reqSize, + ctx.resSize, responseTimes.min, responseTimes.max, responseTimes.sum