diff --git a/package-lock.json b/package-lock.json index d1e9b9b..8f69a44 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "express-status-monitor", - "version": "1.2.11", + "version": "1.3.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1340,6 +1340,7 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/event-loop-stats/-/event-loop-stats-1.2.0.tgz", "integrity": "sha512-h/leAlXqoEf+D9w1dnFG0srR5vfIq59rLm9PHzcl3/GwFppd+UR46UMuLdp/mvJvuA+MjSd/dNShmuM2/dPFFw==", + "optional": true, "requires": { "nan": "^2.14.0" } @@ -2486,7 +2487,8 @@ "nan": { "version": "2.14.0", "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz", - "integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==" + "integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==", + "optional": true }, "natural-compare": { "version": "1.4.0", diff --git a/package.json b/package.json index e5efdc8..2fcd559 100644 --- a/package.json +++ b/package.json @@ -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": [ @@ -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", @@ -80,4 +82,4 @@ "snyk": "1.305.0" }, "snyk": true -} \ No newline at end of file +} diff --git a/src/helpers/gather-os-metrics.js b/src/helpers/gather-os-metrics.js index a279e23..c886a02 100644 --- a/src/helpers/gather-os-metrics.js +++ b/src/helpers/gather-os-metrics.js @@ -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, @@ -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()) {