Socket
Socket
Sign inDemoInstall

procfs-stats

Package Overview
Dependencies
8
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.3 to 0.0.4

test/custompath.js

112

index.js

@@ -6,7 +6,12 @@

// read the procfs stat file for a pid
module.exports = function(pid,cb){ // or task: ":pid/task/:tid"
module.exports = function(pid/*,procpath*/,cb){ // or task: ":pid/task/:tid"
var pp = _pp(arguments,1);
var procPath = pp.procPath
cb = pp.cb;
var o = {
pid:pid,
stat:function(cb){
fs.readFile("/proc/"+pid+'/stat',function(err,data){
fs.readFile(procPath+pid+'/stat',function(err,data){
if(err) return cb(err);

@@ -17,5 +22,5 @@ var values = data.toString().trim().split(" ");

},
// memory stat file
// memory stat file
statm:function(cb){
fs.readFile('/proc/'+pid+'/statm',function(err,buf){
fs.readFile(procPath+pid+'/statm',function(err,buf){
if(err) return cb(err);

@@ -28,8 +33,8 @@ var values = buf.toString().trim().split(/\s+/g)

status:function(cb){
fs.readFile('/proc/'+pid+'/status',function(err,buf){
fs.readFile(procPath+pid+'/status',function(err,buf){
cb(err,kv(buf));
});
},
argv:function(cb){
fs.readFile('/proc/'+pid+'/cmdline',function(err,buf){
argv:function(cb){
fs.readFile(procPath+pid+'/cmdline',function(err,buf){
cb(err,nulldelim(buf));

@@ -39,8 +44,8 @@ });

env:function(cb){
fs.readFile('/proc/'+pid+'/environ',function(err,buf){
fs.readFile(procPath+pid+'/environ',function(err,buf){
cb(err,nulldelim(buf));
});
});
},
cwd:function(cb){
fs.readlink("/proc/"+pid+"/cwd",function(err,path){
fs.readlink(procPath+pid+"/cwd",function(err,path){
cb(err,path);

@@ -50,3 +55,3 @@ })

io:function(cb){
fs.readFile('/proc/'+pid+'/io',function(err,buf){
fs.readFile(procPath+pid+'/io',function(err,buf){
if(err) return cb(err);

@@ -57,3 +62,3 @@ cb(false,kv(buf));

fds:function(cb){
var fddir = '/proc/'+pid+'/fd';
var fddir = procPath+pid+'/fd';
fs.readdir(fddir,function(err,fds){

@@ -69,3 +74,3 @@ if(err) return cb(err);

// read the number of threads running out of the tasks dir
var fddir = '/proc/'+pid+'/task';
var fddir = procPath+pid+'/task';
fs.readdir(fddir,function(err,fds){

@@ -88,8 +93,13 @@ if(err) return cb(err);

// path to /proc
module.exports.PROC = '/proc/';
// stat fd, get full path, get type/socket type..
module.exports.fd = function(fdlink,cb){
fs.readlink(fdlink,function(err,p){
if(err) return cb(err);
var infop = fdlink.split('/');
var id = infop.pop();
var id = infop.pop();

@@ -106,3 +116,3 @@ var out = {

var c = 1, done = function(){
if(!--c) cb(false,out);
if(!--c) cb(false,out);
}

@@ -129,3 +139,8 @@

module.exports.cpu = function(cb){
fs.readFile('/proc/stat',function(err,buf){
var pp = _pp(arguments);
var procPath = pp.procPath
cb = pp.cb;
fs.readFile(procPath+'stat',function(err,buf){
if(err) return cb(err);

@@ -153,3 +168,7 @@ var lines = buf.toString().trim().split("\n");

module.exports.tcp = function(cb){
fs.readFile("/proc/net/tcp",function(err,buf){
var pp = _pp(arguments);
var procPath = pp.procPath
cb = pp.cb;
fs.readFile(procPath+"net/tcp",function(err,buf){
var t = nettable(buf);

@@ -166,3 +185,8 @@ t.forEach(function(con){

module.exports.udp = function(cb){
fs.readFile("/proc/net/udp",function(err,buf){
var pp = _pp(arguments);
var procPath = pp.procPath
cb = pp.cb;
fs.readFile(procPath+"net/udp",function(err,buf){
var t = nettable(buf);

@@ -179,3 +203,7 @@ t.forEach(function(con){

module.exports.unix = function(cb){
fs.readFile("/proc/net/unix",function(err,buf){
var pp = _pp(arguments);
var procPath = pp.procPath
cb = pp.cb;
fs.readFile(procPath+"net/unix",function(err,buf){
var lines = buf.toString().trim().split("\n");

@@ -193,3 +221,7 @@ var keys = lines.shift().trim().split(/\s+/);

module.exports.net = function(cb){
fs.readFile("/proc/net/dev",function(err,buf){
var pp = _pp(arguments);
var procPath = pp.procPath
cb = pp.cb;
fs.readFile(procPath+"net/dev",function(err,buf){
cb(err,sectiontable(buf),buf);

@@ -201,3 +233,7 @@ });

module.exports.wifi = function(cb){
fs.readFile("/proc/net/wireless",function(err,buf){
var pp = _pp(arguments);
var procPath = pp.procPath
cb = pp.cb;
fs.readFile(procPath+"net/wireless",function(err,buf){
cb(err,sectiontable(buf),buf);

@@ -208,3 +244,8 @@ });

module.exports.disk = function(cb){
fs.readFile("/proc/diskstats",function(err,buf){
var pp = _pp(arguments);
var procPath = pp.procPath
cb = pp.cb;
fs.readFile(procPath+"diskstats",function(err,buf){
if(err) return cb(err);

@@ -224,3 +265,3 @@

//i wonder if this is useful? you have to be root to get it.
// its not documented and the nr of the syscall though its supposed to be first never gives me the value i expect in the syscall mapping table.
// its not documented and the nr of the syscall though its supposed to be first never gives me the value i expect in the syscall mapping table.
// i checked unistd.h and a few other places for the __NR nr int value it must be another number not listed.

@@ -235,3 +276,3 @@ //module.exports.syscall = function(){

// 232 0x5 0x7fff89a352b0 0x400 0x3e8 0x44 0x7fff89a382f0 0x7fff89a38220 0x7f042d9a9619
// 232 0x5 0x7fff89a352b0 0x400 0x7d0 0x2214350 0x7fff89a382f0 0x7fff89a38158 0x7f042d9a9619
// 232 0x5 0x7fff89a352b0 0x400 0x7d0 0x2214350 0x7fff89a382f0 0x7fff89a38158 0x7f042d9a9619
//}

@@ -331,3 +372,3 @@

s = sections[i].trim();
l = sections[i].length;
l = sections[i].length;
c = columns[i].trim().split(/\s+/g);

@@ -383,3 +424,22 @@ while(c.length) {

args.pop();// remove trailing empty.
return args;
return args;
}
function _pp(a,num){
num = num||0;// number of static args.
// custom proc path is always before the cb.
var args = [].slice.call(a);
// pop off callback
var cb = args.pop();
// shift off preceding args.
for(var i=0;i<num;++i) args.shift();
//i only ever need procpath.
var procPath = args.shift()||module.exports.PROC||'/proc/';
// add missing / if needed.
if(procPath.charAt(procPath.length-1) != '/') procPath += '/';
return {procPath:procPath,cb:cb};
}
{
"name": "procfs-stats",
"version": "0.0.3",
"version": "0.0.4",
"description": "get detailed information (more than ps, top etc) about running process on linux machines from node.",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc