Skip to content

Node.js os.loadavg() for windows (platform independent solution)

License

Notifications You must be signed in to change notification settings

fider/loadavg-windows

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

Use require('loadavg-windows') to enjoy os.loadavg() on Windows OS (or force using custom implementation on any other OS).

Motivation

Currently Node.js on Windows platform do not implements os.loadavg() functionality - it returns [0,0,0]

Important details

  • os.loadavg() returns [A, B, C]
    • A - expect value different than 0 after few seconds.
    • B - expect value different than 0 after first 5 minutes.
    • C - expect value different than 0 after first 15 minutes.
  • Requiring it on other operating systems have NO influence, unless require('loadavg-windows').enableCustomLoadavg() called manually.

Usage

Just one line required to enjoy os.loadavg() on Windows OS:

require('loadavg-windows');

setInterval( () => {
  console.log( os.loadavg() );
}, 3000);

Can be activated on any other OS in case native version not working (on Windows OS it is enabled by default)

const { useCustomLoadavg } = require('loadavg-windows');
useCustomLoadavg();

Installation

Requires Node.js v4.8.7

npm install loadavg-windows

Not important details:

This is pure JavaScript, platform-independent implementation of os.loadavg() that can be used on Windows system (or any other system that for some reasons do not supports loadavg)

It uses only os.cpus() for proper calculations.

Test of version [email protected]

  • First chart demonstrates results during 4h runtime with sample every 21 seconds.
  • Second chart is to check for memory leaks. Memory consumption includes also http server (no memory leaks).

image

About

Node.js os.loadavg() for windows (platform independent solution)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published