Giter Site home page Giter Site logo

nsutil's Introduction

Nsutil.js

Node.js system utilities

NPM

##Summary

  • a distribution of psutil, rebuilt with Node.js
  • support OSX & Linux

##Install

npm install nsutil

##Prebuilt binaries (node v0.10.28)

OSX 64-bit
Linux 64-bit
Linux 32-bit

##Rebuild (if you need)

node-gyp configure build

##Usage

var ns = require('nsutil')

// synchronous with return
res = ns.cpuTimes()

// callback (asynchronous or synchronous)
ns.cpuTimes(function(err, res) {
    if (!err) console.log(res);
})

// output => 
 { user: 40.76, nice: 118.53, system: 683.01, idle: 287470.94 }

##APIs

####CPU

#####[Function] cpuTimes

// sync
res = ns.cpuTimes()

// callback
ns.cpuTimes(function(err, res) { ... });

// output => 
{ user: 40.76, nice: 118.53, system: 683.01, idle: 287470.94 }

#####[Function] perCpuTimes

// sync
res = ns.perCpuTimes()
    
// callback
ns.perCpuTimes(function(err, res) { ... })

// output =>
 [ { user: 174.18, nice: 0, sys: 123.64, idle: 1411.73 },
   { user: 68.05,  nice: 0, sys: 42.15,  idle: 1599.30 },
   { user: 129.05, nice: 0, sys: 62.55,  idle: 1517.90 },
   { user: 58.15,  nice: 0, sys: 28.77,  idle: 1622.58 } ] 

#####[Function] cpuCountLogical (cpuCountPhysical)

// sync
res = ns.cpuCountLogical()

// callback
ns.cpuCountLogical(function(err, res) { ... })

// output =>
 2

####Memory

#####[Function] virtualMemory

// sync
res = ns.virtualMemory()

// callback
ns.virtualMemory(function(err, res) { ... })

// output =>
 // OSX
 { total:    4294967296,
   active:   1476833280,
   avail:    1163386880,
   used:     3606433792,
   free:     237256704,
   inactive: 926130176,
   wire:     1203470336 }
 // Linux
 { total:    383238144,
   active:   66637824,
   avail:    315265024,
   used:     206503936,
   free:     176734208,
   inactive: 71880704,
   buffers:  25927680,
   cached:   112603136 }

#####[Function] swapMemory

// sync
res = ns.swapMemory()

// callback
ns.swapMemory(function(err, res) { ... });

// output =>
 { total: 1073741824,
   used:  6815744,
   free:  1066926080,
   sin:   2724483072,
   sout:  20860928 }    

####Disks

#####[Function] diskUsage

// sync
res = ns.diskUsage('/')

// callback
ns.diskUsage('/', function(err, res) { ... })

// output => unit:bytes
 { free:  816916015625,
   total: 1148920703125,
   used:  10647291015625 }

#####[Function] diskPartitions

// sync
res = ns.diskPartitions()

// callback
ns.diskPartitions(function(err, res) { ... })

// output =>
 [ { device: '/dev/disk0s2',
     mount_point: '/',
     fs_type: 'hfs',
     options: 'rw,local,rootfs,dovolfs,journaled,multilabel' },
   { device: 'devfs',
     mount_point: '/dev',
     fs_type: 'devfs',
     options: 'rw,local,dontbrowse,multilabel' },
     ...] 

#####[Function] diskIOCounters

// sync
res = ns.diskIOCounters()

// callback
ns.diskIOCounters(function(err, res) { ... })

// output =>
 { disk0: 
   { reads: 1170484,
     writes: 668337,
     read_bytes: 18236701696,
     write_bytes: 21262711296,
     read_time: 825561,
     write_time: 540807 },
   disk1:
   { reads: 11704,
     writes: 6683,
     read_bytes: 182367016,
     write_bytes: 212627112,
     read_time: 8255,
     write_time: 5408 }
   ...}      

####Network

#####[Function] netConnections

// sync
res = ns.netConnections()

// callback
ns.netConnections(function(err, res) { ... })

// output =>
 [ { fd: 22,
     family: 'AF_INET',
     type: 'SOCK_STREAM',
     laddr: ['X.X.X.X', XXXX],
     raddr: ['X.X.X.X', XXXX],
     state: 'ESTABLISHED' },
    ...]

#####[Function] netIOCounters

// sync
res = ns.netIOCounters()

// callback
ns.netIOCounters(function(err, res) { ... })

// output => 
 { bridge0: 
   { obytes: 684,
     ibytes: 0,
     opkts: 2,
     ipkts: 0,
     oerrs: 0,
     ierrs: 0,
     iqdrops: 0 },
  en0: 
   { obytes: 160304770,
     ibytes: 2578607670,
     opkts: 1614175,
     ipkts: 2421909,
     oerrs: 0,
     ierrs: 0,
     iqdrops: 0 },
  ...}

####Other system info

#####[Function] bootTime

// sync
res = ns.bootTime()

// callback
ns.bootTime(function(err, res) { ... })

// output =>
 1400543744000 // timestamp ms

#####[Function] users

// sync
res = ns.users()

// callback
ns.users(function(err, res) { ... })

// output =>
 [
  {"username":"Dx.Yang", "tty":"console", "host":"", "startTime":1400548608},
  {"username":"Dx.Yang", "tty":"ttys000", "host":"", "startTime":1400548608},
  {"username":"Dx.Yang", "tty":"ttys001", "host":"", "startTime":1400548608}
 ]

####Process management

#####[Function] pids

// sync
res = ns.pids()

// callback
ns.pids(function(err, res) { ... })

// output =>
 [6652,6651,6640,6639,6638,6633,6632,6615,6606...]

####[Class] Process

// only sync
proc = ns.Process(6652) // arguments[0] is a pid
// return a instance of Process

#####[Method] proc.name

// sync
res = proc.name()

// callback
proc.name(function(err, res) { ... })

// output =>
 'node'

#####[Method] proc.exe

// sync
res = proc.exe()

// callback
proc.exe(function(err, res) { ... })

// output =>
 '/usr/local/bin/node'

#####[Method] proc.cmdline

// sync
res = proc.cmdline()

// callback
proc.cmdline(function(err, res) { ... })

// output =>
 [ 'node',
   '/usr/local/lib/node_modules/mocha/bin/_mocha',
   'test_osx.js',
   '-R',
   'spec' ]

#####[Method] proc.ppid

// sync
res = proc.ppid()

// callback
proc.ppid(function(err, res) { ... })

// output =>
 6651  //parent process id    

#####[Method] proc.cwd

// sync
res = proc.cwd()

// callback
proc.cwd(function(err, res) { ... })

// output =>
 '/Users/node_modules/nsutil/test'

#####[Method] proc.uids

// sync
res = proc.uids()

// callback
proc.uids(function(err, res) { ... })

// output =>
 { real: 501, effective: 501, saved: 501 }

#####[Method] proc.gids

// sync
res = proc.gids()

// callback
proc.gids(function(err, res) { ... })

// output =>
 { real: 20, effective: 20, saved: 20 }

#####[Method] proc.terminal

// sync
res = proc.terminal()

// callback
proc.terminal(funciton(err, res) { ... })

// output =>
 '/dev/ttys004'

#####[Method] proc.memoryInfo

// sync
res = proc.memoryInfo()   

// callback
proc.memoryInfo(function(err, res) { ... })

// output =>
 { rss: 18440192, vms: 3119169536 }

#####[Method] proc.cpuTimes

// sync
res = proc.cpuTimes()

// callback
proc.cpuTimes(function(err, res) { ... })

// output =>
 { user: 0.139774113, sys: 0.027113125 }

#####[Method] proc.createTime

// sync
proc.createTime()

// callback
proc.createTime(function(err, res) { ... })

// output => 
 1400565545000 // timestamp ms

#####[Method] proc.numCtxSwitches

// sync
res = proc.numCtxSwitches()

// callback
proc.numCtxSwitches(function(err, res) { ... })

// output =>
 { voluntary: 32, involuntary: 4 } 

#####[Method] proc.numThreads

// sync
res = proc.numThreads()

// callback
proc.numThreads(function(err, res) { ... })

// output =>
 4

#####[Method] proc.openFiles

// sync
res = proc.openFiles()

// callback
proc.openFiles(function(err, res) { ... })

// output =>
 [ { path: '/dev/ttys004', fd: 0 },
   { path: '/dev/ttys004', fd: 1 },
   { path: '/dev/ttys004', fd: 2 },
  ... ]

#####[Method] proc.connections

// sync
res = proc.connections()    // default is 'all'
// or
res = proc.connections('inet') // or tcp、tcp4、tcp6、udp、udp4、udp6、unix、inet、inet4、inet6

// callback
proc.connections(function(err, res) { ... })
// or
proc.connections('inet', function(err, res) { ... })

// output =>
 [ { fd: 22,
     family: 'AF_INET',
     type: 'SOCK_STREAM',
     laddr: ['X.X.X.X', XXXX],
     raddr: ['X.X.X.X', XXXX],
     state: 'ESTABLISHED' },
    ...] 

#####[Method] proc.numFds

// sync
res = proc.numFds()

// callback
proc.numFds(function(err, res) { ... })

// output =>
 12

#####[Method] proc.getNice

// sync
res = proc.getNice()

// callback
proc.getNice(function(err, res) { ... })

// output =>
 0

#####[Method] proc.setNice

// sync
res = proc.setNice(10) // arguments[0] is nice value

// callback
proc.setNice(10, function(err, res) { ... });

// output =>
     0 // success
    -1 // fail

#####[Method] proc.status

// sync
res = proc.status()

// callback
proc.status(function(err, res) { ... })

// output =>
 'running'

#####[Method] proc.threads

// sync
res = proc.threads()

// callback
proc.threads(function(err, res) { ... })

// output =>
 [ { idx: 1, 
     user: 0.14695000648498535, 
     sys: 0.02574799954891205 },
   { idx: 2,
     user: 0.00007100000220816582,
     sys: 0.00008600000001024455 },
   { idx: 3,
     user: 0.00002499999936844688,
     sys: 0.00008499999967170879 },
   { idx: 4,
     user: 0.0006169999833218753,
     sys: 0.0019920000340789557 } ]

#####[Method] proc.memMaps

// sync
res = proc.memMaps()

// callback
proc.memMaps(function(err, res) { ... })

// output =>
 // OSX
 [
    {
        "pmmap_ext" : "0000000100000000-0000000100617000",
        "addr_perms" : "r-x/rwx",
        "path":"/usr/local/bin/node",
        "rss" : 45056,
        "private" : 0,
        "swapped" : 0,
        "dirtied" : 0,
        "ref_count" : 7,
        "shadow_depth" : 1
    },
    ...]
 // Linux
 [
    {  
        "pmmap_ext": "7f1517342000-7f151734e000",
        "addr_perms": "r-xp",
        "path": "/lib/x86_64-linux-gnu/libnss_files-2.17.so",
        "Size": 49152,
        "Rss": 0, 
        "Pss": 0, 
        "Shared_Clean": 0, 
        "Shared_Dirty": 0, 
        "Private_Clean": 0,
        "Private_Dirty": 0,
        "Referenced": 0,
        "Anonymous": 0,
        "AnonHugePages": 0,
        "Swap": 0,
        "KernelPageSize": 4096,
        "MMUPageSize": 4096,
        "Locked": 0
    },
    ...]

#####[Method] proc.ioCounters (Linux only)

// sync
res = proc.ioCounters()

// callback
proc.ioCounters(function(err, res) { ... })

// output=>
 { rcount: 20474, wcount: 14600, rbytes: 2109440, wbytes: 8192 }

nsutil's People

Contributors

x6doooo avatar sweetpi avatar

Stargazers

wenye avatar ws7she avatar  avatar LancerComet avatar GuozhiSun avatar Jixian Wang avatar Marko Jankovic avatar jian avatar Cui avatar Marwan Hilmi avatar dijkpicy avatar Loïck Bonniot avatar  avatar Mark Griffiths avatar David Grelaud avatar Harald Haesler avatar J. J. Knudsen avatar Dimitris Messinis avatar youxiachai avatar

Watchers

James Cloos avatar  avatar  avatar

nsutil's Issues

/lib/libc.so.6: version `GLIBC_2.13' not found

Hi,

Under Debian Lenny(v5) and Squeeze (v6), I've this mistake:

module.js:356
  Module._extensions[extension](this, filename);
                               ^
Error: /lib/libc.so.6: version `GLIBC_2.13' not found (required by /myscript/node_modules/nsutil/build/Release/x64/nsutil_linux.node)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/myscript/node_modules/nsutil/src/nsutil/nslinux.js:8:14)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)

How to resolve this problem?

install failed

Hello, attempted to install with npm install nsutil

but npm returned a pile of errors:

errors.txt

Hoping you can help because this looks like a very good module

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.