Socket
Socket
Sign inDemoInstall

os-utils

Package Overview
Dependencies
0
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.9 to 0.0.10

129

lib/osutils.js
var _os = require('os');
exports.platform = function(){
return process.platform;
return process.platform;
}
exports.cpuCount = function(){
return _os.cpus().length;
return _os.cpus().length;
}
exports.sysUptime = function(){
//seconds
return _os.uptime();
//seconds
return _os.uptime();
}
exports.processUptime = function(){
//seconds
return process.uptime();
//seconds
return process.uptime();
}

@@ -24,5 +24,4 @@

// Memory
exports.freemem = function(){
return _os.freemem() / ( 1024 * 1024 );
return _os.freemem() / ( 1024 * 1024 );
}

@@ -32,9 +31,36 @@

return _os.totalmem() / ( 1024 * 1024 );
return _os.totalmem() / ( 1024 * 1024 );
}
exports.freememPercentage = function(){
return _os.freemem() / _os.totalmem();
return _os.freemem() / _os.totalmem();
}
// Hard Disk Drive
exports.harddrive = function(callback){
require('child_process').exec('df -h', function(error, stdout, stderr) {
var total = 0;
var used = 0;
var free = 0;
var lines = stdout.split("\n");
var str_disk_info = lines[1].replace( /[\s\n\r]+/g,' ');
var disk_info = str_disk_info.split(' ');
total = disk_info[1]
used = disk_info[2]
free = disk_info[3]
callback(total, free, used);
});
}
/*

@@ -45,11 +71,11 @@ * Returns the load average usage for 1, 5 or 15 minutes.

if(_time === undefined || (_time !== 5 && _time !== 15) ) _time = 1;
if(_time === undefined || (_time !== 5 && _time !== 15) ) _time = 1;
var loads = _os.loadavg();
var v = 0;
if(_time == 1) v = loads[0];
if(_time == 5) v = loads[1];
if(_time == 15) v = loads[2];
var loads = _os.loadavg();
var v = 0;
if(_time == 1) v = loads[0];
if(_time == 5) v = loads[1];
if(_time == 15) v = loads[2];
return v;
return v;
}

@@ -59,7 +85,7 @@

exports.cpuFree = function(callback){
getCPUUsage(callback, true);
getCPUUsage(callback, true);
}
exports.cpuUsage = function(callback){
getCPUUsage(callback, false);
getCPUUsage(callback, false);
}

@@ -69,46 +95,49 @@

var stats1 = getCPUInfo();
var startIdle = stats1.idle;
var startTotal = stats1.total;
var stats1 = getCPUInfo();
var startIdle = stats1.idle;
var startTotal = stats1.total;
setTimeout(function() {
var stats2 = getCPUInfo();
var endIdle = stats2.idle;
var endTotal = stats2.total;
setTimeout(function() {
var stats2 = getCPUInfo();
var endIdle = stats2.idle;
var endTotal = stats2.total;
var idle = endIdle - startIdle;
var total = endTotal - startTotal;
var perc = idle / total;
var idle = endIdle - startIdle;
var total = endTotal - startTotal;
var perc = idle / total;
if(free === true)
callback( perc );
else
callback( (1 - perc) );
if(free === true)
callback( perc );
else
callback( (1 - perc) );
}, 1000 );
}, 1000 );
}
function getCPUInfo(callback){
var cpus = _os.cpus();
var cpus = _os.cpus();
var user = 0;
var nice = 0;
var sys = 0;
var idle = 0;
var irq = 0;
var total = 0;
var user = 0;
var nice = 0;
var sys = 0;
var idle = 0;
var irq = 0;
var total = 0;
for(var cpu in cpus){
for(var cpu in cpus){
user += cpus[cpu].times.user;
nice += cpus[cpu].times.nice;
sys += cpus[cpu].times.sys;
irq += cpus[cpu].times.irq;
idle += cpus[cpu].times.idle;
}
user += cpus[cpu].times.user;
nice += cpus[cpu].times.nice;
sys += cpus[cpu].times.sys;
irq += cpus[cpu].times.irq;
idle += cpus[cpu].times.idle;
}
var total = user + nice + sys + idle + irq;
var total = user + nice + sys + idle + irq;
return {'idle': idle, 'total': total};
return {
'idle': idle,
'total': total
};
}
{
"name" : "os-utils",
"version" : "0.0.9",
"version" : "0.0.10",
"description" : "an operating-system utility library",

@@ -5,0 +5,0 @@ "url" : "http://oscar-mejia.com",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc