os.cpus()
获取当前机器的CPU信息
const os = require('os')
console.log(os.cpus())
打印结果:
[ { model: 'Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz', speed: 2300, times: { user: 1332960, nice: 0, sys: 928720, idle: 5905010, irq: 0 } }, { model: 'Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz', speed: 2300, times: { user: 684730, nice: 0, sys: 490170, idle: 6991300, irq: 0 } }, { model: 'Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz', speed: 2300, times: { user: 1315900, nice: 0, sys: 741750, idle: 6108540, irq: 0 } }, { model: 'Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz', speed: 2300, times: { user: 596770, nice: 0, sys: 406270, idle: 7163160, irq: 0 } } ]
os.totalmem()
获取当前机器的内存总量,单位为字节
const os = require('os')
console.log(os.totalmem())
打印结果:
17179869184
单位为字节,除以1024为KB,再除以1024为MB,再除以1024为GB(上面的结果为16GB)