How to get system statistics with node.js

On Linux, you can use /proc. See here for a bunch of command line examples to read the stats.

It would be better to read the files from Node directly though, using fs.readFile()

Update: There is also the OS API which is probably better. Example usage: Convert the output of os.cpus() in Node.js to percentage


IMHO the best option is to use the systeminformation module,

where you can retrieve detailed hardware, system, and OS information with Linux, macOS, partial Windows, and FreeBSD support.

For example to get the CPU information:

const si = require('systeminformation');

// callback style
si.cpu(function(data) {
    console.log('CPU-Information:');
    console.log(data);
});

// promises style - new in version 3
si.cpu()
    .then(data => console.log(data))
    .catch(error => console.error(error));

// full async / await example (node >= 7.6)
async function cpu() {
    try {
        const data = await si.cpu();
        console.log(data)
    } catch (e) {
        console.log(e)
    }
}

This example will result the following:

{ manufacturer: 'Intel®',
    brand: 'Core™ i5-3317U',
    vendor: 'GenuineIntel',
    family: '6',
    model: '58',
    stepping: '9',
    revision: '',
    voltage: '',
    speed: '1.70',
    speedmin: '0.80',
    speedmax: '2.60',
    cores: 4,
    cache: { l1d: 32768, l1i: 32768, l2: 262144, l3: 3145728 } }
CPU-Information:
{ manufacturer: 'Intel®',
    brand: 'Core™ i5-3317U',
    vendor: 'GenuineIntel',
    family: '6',
    model: '58',
    stepping: '9',
    revision: '',
    voltage: '',
    speed: '1.70',
    speedmin: '0.80',
    speedmax: '2.60',
    cores: 4,
    cache: { l1d: 32768, l1i: 32768, l2: 262144, l3: 3145728 } }