I’m making Linux monitoring program. I’m working with Node.js so I used os module.
I heard that formula for Linux CPU usage percentage per core is
(user+nice+system+idle+irq)/(user+nice+system) ×100 (those things got from os.cpus())
so I created code which calculate that and
got Entire Linux CPU usage percentage for Using (sum of all of core Usage percentage)/cpu core count.
I got 3.8%.
I wanted to make sure whether this was exact or not, so I ran
top -bn1 | grep "Cpu(s)" | awk '{printf("CPU usage : %.1f%%n", 100 - $8)}'
too at the same time in kernel.
and kernel says it’s 8.5%.
I know I just ran kernel command In Node.js and got usage percentage but the thing I really want to know about is why (or how) is this happened and what is the exact meaning of CPU Usage.
I’m not familiar with this Os mechanism or something like that. Can someone let me know about these?