Design Complete Monitor for System Uptime and Load Average
🚀 Building a CPU & Memory Monitor in Node.js node:os module imports the CPU info, memory info , uptime, system-level stats they all are coming from the os module. we design a function named monitor which calculate the CPU and Memory usage. oldCpus=os.cpus(); : This is calculating the cpus info like idle time, user time, system time etc. we call a method setTimeout() : This will call repeatly os.cpus() method for the comparison purpose . Like idle=newCpus-oldCpus const newCpus=os.cpus(); : This calculate the new cpus stats. const usage = newCpus.map((cpu, idx) => { return { core: idx, usage: calculateCPU(oldCpus[idx], newCpus[idx]) + "%", }; }); This is calculating the usage for CPU Core where loop will execute for every core with the help of map() method and calculate the usage percentage = calculateCPU(oldCpus[idx], newCpus[idx]) output like: ...