From c0a2208b984fadb0346de70749bfbb756c238572 Mon Sep 17 00:00:00 2001 From: Gergely Nemeth Date: Sun, 14 Feb 2016 12:39:47 +0100 Subject: [PATCH] fix(event-loop): get values from libuv --- lib/providers/apmMetrics/index.js | 27 +++----------------------- lib/providers/apmMetrics/index.spec.js | 14 +++++++++++-- package.json | 2 +- 3 files changed, 16 insertions(+), 27 deletions(-) diff --git a/lib/providers/apmMetrics/index.js b/lib/providers/apmMetrics/index.js index b5e13d2..2173344 100644 --- a/lib/providers/apmMetrics/index.js +++ b/lib/providers/apmMetrics/index.js @@ -1,6 +1,6 @@ var os = require('os') -var blocked = require('blocked') -var gc = (require('gc-stats'))() +var gc = require('gc-stats')() +var eventLoopStats = require('event-loop-stats') var BYTES_TO_MEGABYTES = 1024 * 1024 @@ -15,8 +15,6 @@ function ApmMetrics (eventBus) { scavenge: 0, marksweep: 0 } - this.eventLoopLag = {} - this.eventLoopLag[this.lagId] = [] var _this = this @@ -41,10 +39,6 @@ function ApmMetrics (eventBus) { break } }) - - blocked(function (ms) { - _this.eventLoopLag[_this.lagId].push(ms) - }) } ApmMetrics.prototype.getMetrics = function () { @@ -83,17 +77,8 @@ ApmMetrics.prototype._bytesToMegaBytes = function (bytes) { } ApmMetrics.prototype.getEventLoop = function () { - this.eventLoopLag[++this.lagId] = [] - if (this.eventLoopLag[this.lagId - 2]) { - delete this.eventLoopLag[this.lagId - 2] - } - - var eventLoopLag = this.eventLoopLag[this.lagId - 1].reduce(function (total, curr) { - return total + curr - }, 0) - return { - lag: eventLoopLag, + stats: eventLoopStats.sense(), requests: process._getActiveRequests().length, handlers: process._getActiveHandles().length } @@ -105,12 +90,6 @@ ApmMetrics.prototype.reset = function () { scavenge: 0, marksweep: 0 } - - this.eventloop = { - lag: 0, - requests: 0, - handlers: 0 - } } function create (eventBus) { diff --git a/lib/providers/apmMetrics/index.spec.js b/lib/providers/apmMetrics/index.spec.js index e3e0148..66995b7 100644 --- a/lib/providers/apmMetrics/index.spec.js +++ b/lib/providers/apmMetrics/index.spec.js @@ -1,5 +1,6 @@ var expect = require('chai').expect var os = require('os') +var eventLoopStats = require('event-loop-stats') var ApmMetrics = require('./') @@ -21,6 +22,13 @@ describe('The ApmMetrics module', function () { var memoryTotal = 12000000 var memoryRss = 15000000 + var _eventLoopStats = { + max: 10, + min: 0, + sum: 100, + num: 32 + } + var event = { emit: function (name, data) { expect(name).to.eql('apm') @@ -33,7 +41,7 @@ describe('The ApmMetrics module', function () { eventloop: { handlers: activeHandlers, requests: activeRequests, - lag: 30 + stats: _eventLoopStats }, cpu: { utilization: Math.floor(loadAvg) @@ -53,8 +61,10 @@ describe('The ApmMetrics module', function () { var apmMetrics = ApmMetrics.create(event) apmMetrics.lagId = 1 - apmMetrics.eventLoopLag[1] = [10, 20] + this.sandbox.stub(eventLoopStats, 'sense', function () { + return _eventLoopStats + }) this.sandbox.stub(process, '_getActiveRequests', function () { return new Array(activeRequests) }) diff --git a/package.json b/package.json index f3cdb54..cc367b5 100644 --- a/package.json +++ b/package.json @@ -35,9 +35,9 @@ }, "dependencies": { "bl": "1.0.1", - "blocked": "1.1.0", "continuation-local-storage": "3.1.6", "debug": "2.2.0", + "event-loop-stats": "1.0.0", "gc-stats": "1.0.0", "lodash.defaults": "4.0.1", "microtime": "2.0.0",