Listen for system utilization, like CPU and memory, that exceeds a desired threshold.
npm install utilization-listenerListen for system utilization, like CPU and memory, that
exceeds a desired threshold.
```
$ npm install --save utilization-listener
`js
import UtilizationListener from 'utilization-listener'
const utilization = UtilizationListener()
// using async/await
(async function() {
await utilization.start({
type: 'memory', // 'memory' or 'cpu'
interval: 50, // milliseconds to determine how often to poll for utilization to check if it exceeds threshold
percentThreshold: 80 // means if the utilization for the type provided exceeds 80%, invoke callbackthreshold
}, function(threshold) => { // callback: only invoked if is above percentThreshold in utilization.start() definitionutilization.end()
console.log(threshold) // ex. 98.54723
this.end() // also can call via : ends the listener and resolves the promise returned from utilization.start()
})
console.log('We stopped polling for utilization!')
})()
// using promises
utilization.start({
type: 'memory',
interval: 50,
percentThreshold: 80
}, function(threshold) => {
console.log(threshold)
this.end()
}).then(() => console.log('We stopped polling for utilization!'))
`
```
$ git clone https://github.com/useriq-com/useriq-utilization-listener
$ cd useriq-utilization-listener
$ npm install
$ npm test