Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 3 additions & 24 deletions lib/providers/apmMetrics/index.js
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -15,8 +15,6 @@ function ApmMetrics (eventBus) {
scavenge: 0,
marksweep: 0
}
this.eventLoopLag = {}
this.eventLoopLag[this.lagId] = []

var _this = this

Expand All @@ -41,10 +39,6 @@ function ApmMetrics (eventBus) {
break
}
})

blocked(function (ms) {
_this.eventLoopLag[_this.lagId].push(ms)
})
}

ApmMetrics.prototype.getMetrics = function () {
Expand Down Expand Up @@ -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
}
Expand All @@ -105,12 +90,6 @@ ApmMetrics.prototype.reset = function () {
scavenge: 0,
marksweep: 0
}

this.eventloop = {
lag: 0,
requests: 0,
handlers: 0
}
}

function create (eventBus) {
Expand Down
14 changes: 12 additions & 2 deletions lib/providers/apmMetrics/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var expect = require('chai').expect
var os = require('os')
var eventLoopStats = require('event-loop-stats')

var ApmMetrics = require('./')

Expand All @@ -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')
Expand All @@ -33,7 +41,7 @@ describe('The ApmMetrics module', function () {
eventloop: {
handlers: activeHandlers,
requests: activeRequests,
lag: 30
stats: _eventLoopStats
},
cpu: {
utilization: Math.floor(loadAvg)
Expand All @@ -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)
})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down