Skip to content

Commit

Permalink
Better compatibility with older node.js versions
Browse files Browse the repository at this point in the history
  • Loading branch information
devmirek committed Mar 24, 2021
1 parent c561f1c commit 8972a1d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions node_js/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8972a1d

Please sign in to comment.