Code Monkey home page Code Monkey logo

os-utils's Introduction

os-utils

An operating system utility library. Some methods are wrappers of node libraries and others are calculations made by the module.

Installation

One line installation with npm.

npm install os-utils

Then in your code

var os 	= require('os-utils');


os.cpuUsage(function(v){
	console.log( 'CPU Usage (%): ' + v );
});

os.cpuFree(function(v){
	console.log( 'CPU Free:' + v );
});

Usage

The following methods are available:

Calculate CPU usage for the next second

This is not an average of CPU usage like it is in the "os" module. The callback will receive a parameter with the value.

os.cpuUsage( function(value) { /* ... */ } );

Calculate free CPU for the next second

This is not based on average CPU usage like it is in the "os" module. The callback will receive a parameter with the value.

os.cpuFree( function(value) { /* ... */ } );

Get the platform name

os.platform();

Get number of CPUs

os.cpuCount()

Get current free memory

os.freemem()

Get total memory

os.totalmem()

Get a current free memory percentage

os.freememPercentage()

Get the number of seconds the system has been running for

os.sysUptime();

Get the number of seconds the process has been running

os.processUptime() 

Get average load for 1, 5 or 15 minutes

os.loadavg(1)
os.loadavg(5)
os.loadavg(15)

os-utils's People

Contributors

amilajack avatar bluefirex avatar emilebons avatar empirefx avatar fidian avatar lorenzos avatar oscmejia avatar wmramadan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

os-utils's Issues

TypeError: os.cpuUsage is not a function

os.cpuUsage(function (v) {
   ^

TypeError: os.cpuUsage is not a function

I'm used example code:

    os.cpuUsage(function (v) {
        console.log('CPU Usage (%): ' + v);
    });

Error with getCPUInfo

I have error on use cpuUsage

node_modules\os-utils\lib\osutils.js:198
        user += cpus[cpu].times.user;
                                ^

TypeError: Cannot read property 'user' of undefined
    at getCPUInfo (D:\Other\Development\Projects\BotDiscord\Kristal-Alp.-\node_modules\os-utils\lib\osutils.js:198:33)
    at getCPUUsage (D:\Other\Development\Projects\BotDiscord\Kristal-Alp.-\node_modules\os-utils\lib\osutils.js:167:18)
    at Object.exports.cpuUsage (D:\Other\Development\Projects\BotDiscord\Kristal-Alp.-\node_modules\os-utils\lib\osutils.js:162:5)
    at Timeout._onTimeout (D:\Other\Development\Projects\BotDiscord\Kristal-Alp.-\bot\Structures\Site.js:45:12)
    at listOnTimeout (internal/timers.js:549:17)
    at processTimers (internal/timers.js:492:7)

And I fixed it by replacing the line:

for (var cpu in cpus) {
        user + = cpus [cpu] .times.user;
        good + = cpu [cpu] .times.nice;
        sys + = cpus [cpu] .times.sys;
        irq + = cpus [cpu] .times.irq;
        idle + = cpus [cpu] .times.idle;
    }

to

    cpus.forEach(cpu => {
        user += cpu.times.user;
        nice += cpu.times.nice;
        sys += cpu.times.sys;
        irq += cpu.times.irq;
        idle += cpu.times.idle;
    })

Seconds/miliseconds

Hi,

I read this from your doc :

Get the number of miliseconds the process has been running :
os.processUptime()

But there is this comment from your code here :

exports.processUptime = function(){ 
   //seconds
    return process.uptime();
}

Is that seconds or milliseconds ?

Bandwidth usage per process

I was planning to build a GUI version of nethogs (it displays bandwidth usage by processes). I wanted to build it using http://electron.atom.io/. My question is would you be willing to add a method to your module that enables this.

You pass it a process ID and it returns uploaded and download kbs.

Thank you.

Work with zram/swap

Functions freemem and totalmem not including a zram/swap and i always got a full ram

Available RAM Memory in Linux not reported

Problem Description:

os.freemem() and os.freememPercentage() only show free memory and not available memory

Solution:

Add available memory from free -m in Linux

Platform:

OS: Ubuntu 21.04
Kernel: 5.11.0-38-generic
NPM: 7.5.2
NODE: 12.21.0
ELECTRON: 16.0.5

cpu usage not correct

I'm using os.cpuUsage as in the example but it doesn't return the right value, it should return somethings bigger than 1, but it never goes above 1%

CPU Usage (%): 0.48840794179306946
 CPU Usage (%): 0.07608901216667718
 CPU Usage (%): 0.027251703231451985
 CPU Usage (%): 0.03877221324717284
CPU Usage (%): 0.05082100268464751
 CPU Usage (%): 0.04029574861367835
CPU Usage (%): 0.02399852316780504
 CPU Usage (%): 0.04997234003319195
 os.cpuUsage((v) => {
    console.log("CPU Usage (%): " + v);
  });

Could you provide aync versions of cpuUsage and cpuFree?

The implementation of cpuUsage and cpuFree uses setTimeout internally. The effect is that these methods are asynchronous but a caller cannot wait for them to complete. Could you provide an implementation (or additional async methods) that do allow the caller to wait for the results?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.