Skip to content

Commit

Permalink
Merge pull request #144 from RafalWilinski/event-loop-optional
Browse files Browse the repository at this point in the history
Event loop optional
  • Loading branch information
RafalWilinski authored Apr 22, 2020
2 parents 9588d4b + 8dcd5de commit b8d43d6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
6 changes: 4 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "express-status-monitor",
"version": "1.3.0",
"version": "1.3.1",
"description": "Realtime Monitoring for Express-based Node applications",
"main": "index.js",
"keywords": [
Expand Down Expand Up @@ -59,12 +59,14 @@
"dependencies": {
"axios": "0.19.2",
"debug": "4.1.1",
"event-loop-stats": "1.2.0",
"handlebars": "^4.7.6",
"on-headers": "1.0.2",
"pidusage": "2.0.18",
"socket.io": "2.3.0"
},
"optionalDependencies": {
"event-loop-stats": "1.2.0"
},
"scripts": {
"test-ci": "mocha --recursive",
"test": "mocha --recursive --watch",
Expand All @@ -80,4 +82,4 @@
"snyk": "1.305.0"
},
"snyk": true
}
}
14 changes: 12 additions & 2 deletions src/helpers/gather-os-metrics.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
const pidusage = require('pidusage');
const os = require('os');
const v8 = require('v8');
const eventLoopStats = require('event-loop-stats');
const sendMetrics = require('./send-metrics');
const debug = require('debug')('express-status-monitor');

let eventLoopStats; // eslint-disable-line

try {
eventLoopStats = require('event-loop-stats'); // eslint-disable-line
} catch (error) {
console.warn('event-loop-stats not found, ignoring event loop metrics...');
}

module.exports = (io, span) => {
const defaultResponse = {
2: 0,
Expand All @@ -29,7 +36,10 @@ module.exports = (io, span) => {
stat.load = os.loadavg();
stat.timestamp = Date.now();
stat.heap = v8.getHeapStatistics();
stat.loop = eventLoopStats.sense();

if (eventLoopStats) {
stat.loop = eventLoopStats.sense();
}

span.os.push(stat);
if (!span.responses[0] || (last.timestamp + span.interval) * 1000 < Date.now()) {
Expand Down

0 comments on commit b8d43d6

Please sign in to comment.