npm install --save instance-stats
const instanceStats = require('instance-stats');
// Get cpu info
let cpus = instanceStats.getCpuInfo();
console.log(cpus);
// Get gpu info. getGpusInfo function return a promise
instanceStats.getGpusInfo()
.then(function(gpus, stderr) {
console.log(gpus);
})
.catch(function(error) {
console.log(error);
})
This library also provide Observer object for getting CPU and GPU usage.
const instanceStats = require('instance-stats');
// Create an observer object which broadcasts infomation every second (1000ms)
const observer = new instanceStats.StatsObserver(1000);
// Listen on CPU event
observer.on('cpu', function(cpuInfo, timestamp) {
// Do something...
});
// Listen on GPU event
observer.on('gpu', function(cpuInfo, timestamp) {
// Do something...
});
// Listen on GPU error event
observer.on('gpu-error', function(error) {
// Do something...
});
// Start the observer
observer.start();
// Stop the observer after 5 seconds (5000ms)
setTimeout(function () {
observer.stop();
}, 5000);
Yeoman has a heart of gold. He's a person with feelings and opinions, but he's very easy to work with. If you think he's too opinionated, he can be easily convinced. Feel free to learn more about him.
Yeoman and Generator-simple-package
MIT © nghiattran