From 8972a1d1c71786f4d9c288d2aed9febb902f024f Mon Sep 17 00:00:00 2001 From: "mirek.malecha@bonitoo.io" Date: Thu, 25 Feb 2021 12:53:40 +0100 Subject: [PATCH] Better compatibility with older node.js versions --- node_js/monitor.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/node_js/monitor.js b/node_js/monitor.js index 27fe5e34..f908e55a 100644 --- a/node_js/monitor.js +++ b/node_js/monitor.js @@ -29,13 +29,16 @@ function writeProcessUsage() { // https://nodejs.org/api/process.html#process_process_cpuusage_previousvalue writeAPI.writePoint(createPoint('node_cpu_usage', process.cpuUsage())) // https://nodejs.org/api/process.html#process_process_resourceusage - writeAPI.writePoint( - createPoint('node_resource_usage', process.resourceUsage()) - ) + // available since node v12.6 + if (process.resourceUsage) { + writeAPI.writePoint( + createPoint('node_resource_usage', process.resourceUsage()) + ) + } } // write process usage now and then every 10 seconds writeProcessUsage() -const nodeUsageTimer = setInterval(writeProcessUsage, 10_000).unref() +const nodeUsageTimer = setInterval(writeProcessUsage, 10000).unref() // on shutdown // - clear reporting of node usage