Skip to content

Instantly share code, notes, and snippets.

View vndeguzman's full-sized avatar

Vic de Guzman vndeguzman

View GitHub Profile
@vndeguzman
vndeguzman / cpu.js
Created September 18, 2018 03:29 — forked from bag-man/cpu.js
How to calculate the current CPU load with Node.js; without using any external modules or OS specific calls.
var os = require("os");
//Create function to get CPU information
function cpuAverage() {
//Initialise sum of idle and time of cores and fetch CPU info
var totalIdle = 0, totalTick = 0;
var cpus = os.cpus();
//Loop through CPU cores
@vndeguzman
vndeguzman / cpu.js
Created September 18, 2018 03:29 — forked from bag-man/cpu.js
How to calculate the current CPU load with Node.js; without using any external modules or OS specific calls.
var os = require("os");
//Create function to get CPU information
function cpuAverage() {
//Initialise sum of idle and time of cores and fetch CPU info
var totalIdle = 0, totalTick = 0;
var cpus = os.cpus();
//Loop through CPU cores