Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

219
Visualizações
how to get server cpu and memory and disk percentage in node.js
var os  = require('os-utils');
os.cpuUsage(function(v){
    console.log( 'os-utils CPU Usage (%): ' + v ); 
    // os-utils CPU Usage (%): 0.11180382377389864
});
os.cpuFree(function(v){
    console.log( 'os-utils CPU Free:' + v );
    // os-utils CPU Free:0.8876135425268373
});

var osu = require('node-os-utils')
var cpu = osu.cpu
cpu.usage()
.then(info => {
    console.log('node-os-utils cpu.usage '+info)
    // node-os-utils cpu.usage 11.53
})
cpu.free()
.then(info => {
    console.log('node-os-utils cpu.free '+ info)
    // node-os-utils cpu.free 88.47
})

it's so annoying. Why is the os-utils value different from the node-os-utils value? I need the CPU and disk memory values ​​of the server currently running node.js -Current CPU usage** (percent) -Available memory* (free/total) -Available disk space (free/total)

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Why is the os-utils value different from the node-os-utils value?

Because one is a percentage (a number between 0 and 100) and one is a number between 0 and 1.

(I would assume that multi-core systems may multiple the maximum number by the number of cores.)

The values are the same. They are just expressed in very slightly different terms.

about 4 years ago · Santiago Trujillo Relatório

0

It seems like os-utils package works well. Just format of percentage was given from 0 to 1, meaning 0 => 0% and 1 => 100% and so on.

About getting disk space volume info you can use package diskusage. You can check docs there https://www.npmjs.com/package/diskusage

const disk = require('diskusage');

// get disk usage. Takes mount point as first parameter
disk.check('/', function(err, info) {
    const freeInPercentage = info.free / info.total;
    const usedInPercentage = info.available / info.total;

    console.log(`free disk space: ${freeInPercentage * 100}%`);
    console.log(`used disk space: ${usedInPercentage * 100}%`);
});
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda