Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
procfs-stats
Advanced tools
get detailed information (more than ps, top etc) about running process on linux machines from node.
get detailed information about running process and threads on linux machines from node. more than ps/top/iostat alone
var procfs = require('procfs-stats');
var ps = procfs(process.pid);
ps.io(function(err,io){
console.log('my process has done this much io',io);
})
this only works on linux right now i expect. some things may work on other systems that have some support for procfs.
it would be so cool to have a higher level module that unifies system monitoring scripts in such a way as each os specific implementation can export a common interface like this and we can have xplatform monitoring helpers!! does windows have any external process introspection api?!
var ps = procfs(process.pid)
console.log(ps);
{ rchar: '84167',
wchar: '15978',
syscr: '107',
syscw: '47',
read_bytes: '0',
write_bytes: '12288',
cancelled_write_bytes: '0' }
{ pid: '8157',
comm: '(node)',
state: 'R',
ppid: '8156',
pgrp: '8150',
session: '1703',
tty_nr: '34822',
tpgid: '8150',
flags: '4202496',
minflt: '3788',
cminflt: '0',
majflt: '0',
cmajflt: '0',
utime: '8',
stime: '1',
cutime: '0',
cstime: '0',
priority: '20',
nice: '0',
num_threads: '6',
itrealvalue: '0',
starttime: '62912348',
vsize: '910020608',
rss: '3277',
rsslim: '18446744073709551615',
startcode: '4194304',
endcode: '12964340',
startstack: '140736757717536',
kstkesp: '140736757701400',
kstkeip: '140541704641018',
signal: '0',
blocked: '0',
sigignore: '4096',
sigcatch: '16898',
wchan: '18446744073709551615',
nswap: '0',
cnswap: '0',
exit_signal: '17',
processor: '0',
rt_priority: '0',
policy: '0',
delayacct_blkio_ticks: '0',
guest_time: '0',
cguest_time: '0' }
{ size: '222173',
resident: '3342',
share: '1284',
text: '2142',
lib: '0',
data: '215399',
dt: '0' }
{ Name: 'node',
State: 'S (sleeping)',
Tgid: '8157',
Pid: '8157',
PPid: '8156',
TracerPid: '0',
Uid: '1000\t1000\t1000\t1000',
Gid: '1000\t1000\t1000\t1000',
FDSize: '64',
Groups: '4 20 24 27 30 46 109 121 1000 ',
VmPeak: '954740 kB',
VmSize: '888692 kB',
VmLck: '0 kB',
VmPin: '0 kB',
VmHWM: '13464 kB',
VmRSS: '13368 kB',
VmData: '861452 kB',
VmStk: '144 kB',
VmExe: '8568 kB',
VmLib: '4084 kB',
VmPTE: '172 kB',
VmSwap: '0 kB',
Threads: '6',
SigQ: '2/63628',
SigPnd: '0000000000000000',
ShdPnd: '0000000000000000',
SigBlk: '0000000000000000',
SigIgn: '0000000000001000',
SigCgt: '0000000180004202',
CapInh: '0000000000000000',
CapPrm: '0000000000000000',
CapEff: '0000000000000000',
CapBnd: 'ffffffffffffffff',
Cpus_allowed: 'ff',
Cpus_allowed_list: '0-7',
Mems_allowed: '00000000,00000001',
Mems_allowed_list: '0',
voluntary_ctxt_switches: '39',
nonvoluntary_ctxt_switches: '29' }
[ ...
'MANPATH=:/usr/local/avr/man:/usr/local/avr/man',
'LS_OPTIONS=--color=auto',
'npm_config_git=git',
'npm_config_optional=true',
'EDITOR=vim',
'npm_config_email=soldair@',
'npm_config_json=' ]
"/home/soldair/opensource/node-procfs-stats"
these are the args for the command node test/pid_argv.js --example
[ 'node',
'test/pid_argv.js',
'--example' ]
[ '/proc/8157/fd/0',
'/proc/8157/fd/1',
'/proc/8157/fd/10',
'/proc/8157/fd/2',
'/proc/8157/fd/9' ]
[ '10299', '10300', '10301', '10302', '10303', '10304' ]
the exported function also has these "static" methods.
var thread = ps.thread(tid);
{ cpu:
{ user: '22865094',
nice: '8419',
system: '41080741',
idle: '120838211',
iowait: '31250',
irq: '13',
softirq: '38550',
steal: '0',
guest: '0',
guest_nice: '0' },
cpu0:
{ user: '5417204',
nice: '1535',
system: '8517931',
idle: '32167970',
iowait: '13554',
irq: '10',
softirq: '33485',
steal: '0',
guest: '0',
guest_nice: '0' },
... more cpus
intr: '779069953 10 0 0 ... so many zeros ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0',
ctxt: '1272813489',
btime: '1389119192',
processes: '104169',
procs_running: '2',
procs_blocked: '0',
softirq: '387055666 39 219612430 63769 2305517 2468782 39 16208198 61170901 82217 85143774' }
{ fd: '/proc/8306/fd/2',
path: '/dev/pts/6',
info: { pos: '0', flags: '02100002' },
stat:
{ dev: 11,
mode: 8576,
nlink: 1,
uid: 1000,
gid: 5,
rdev: 34822,
blksize: 1024,
ino: 9,
size: 0,
blocks: 0,
atime: Tue Jan 14 2014 17:19:04 GMT-0800 (PST),
mtime: Tue Jan 14 2014 17:19:04 GMT-0800 (PST),
ctime: Thu Jan 09 2014 14:28:29 GMT-0800 (PST) }
// if its not a regular file path supported by stat stat is false.
{ path: 'pipe:[19705393]',
info: { pos: '0', flags: '02000000' },
stat: false }
{ path: 'anon_inode:[eventfd]',
info: { pos: '0', flags: '02004002' },
stat: false }
[ ....
{ sl: '10:',
local_address: '127.0.0.1:24599',
rem_address: '0.0.0.0:0',
st: '0A',
tx_queue: '00000000',
rx_queue: '00000000',
tr: '00',
'tm->when': '00000000',
retrnsmt: '00000000',
uid: '118',
timeout: '0',
inode: '12881',
_:
{ '12': '1',
'13': '0000000000000000',
'14': '100',
'15': '0',
'16': '0',
'17': '10',
'18': '-1' } } ]
[ { sl: '1186:',
local_address: '127.0.0.1:52011',
rem_address: '0.0.0.0:0',
st: '07',
tx_queue: '00000000',
rx_queue: '00000000',
tr: '00',
'tm->when': '00000000',
retrnsmt: '00000000',
uid: '116',
timeout: '0',
inode: '12576',
ref: '2',
pointer: '0000000000000000',
drops: '0' },
... ]
[ { Num: '0000000000000000:',
RefCount: '00000002',
Protocol: '00000000',
Flags: '00010000',
Type: '0001',
St: '01',
Inode: '12597',
Path: '/var/run/mysqld/mysqld.sock' },
...]
[{ Interface: 'wlan0:',
bytes: { Receive: '301155854', Transmit: '75294312' },
packets: { Receive: '910966', Transmit: '372927' },
errs: { Receive: '0', Transmit: '0' },
drop: { Receive: '0', Transmit: '0' },
fifo: { Receive: '0', Transmit: '0' },
frame: { Receive: '0' },
compressed: { Receive: '0', Transmit: '0' },
multicast: { Receive: '0' },
colls: { Transmit: '0' },
carrier: { Transmit: '0' } },
{ Interface: 'eth0:',
bytes: { Receive: '1202562365', Transmit: '111732378' },
packets: { Receive: '1868620', Transmit: '608933' },
errs: { Receive: '0', Transmit: '0' },
drop: { Receive: '0', Transmit: '0' },
fifo: { Receive: '0', Transmit: '0' },
frame: { Receive: '0' },
compressed: { Receive: '0', Transmit: '0' },
multicast: { Receive: '102222' },
colls: { Transmit: '0' },
carrier: { Transmit: '0' } }]
[ { device_number: '1',
device_number_minor: '5',
device: 'ram5',
reads_completed: '0',
reads_merged: '0',
sectors_read: '0',
ms_reading: '0',
writes_completed: '0',
writes_merged: '0',
sectors_written: '0',
ms_writing: '0',
ios_pending: '0',
ms_io: '0',
ms_weighted_io: '0' },
... many disks or disk like things...
{ device_number: '8',
device_number_minor: '0',
device: 'sda',
reads_completed: '255428',
reads_merged: '208748',
sectors_read: '9462489',
ms_reading: '368008',
writes_completed: '1604578',
writes_merged: '735675',
sectors_written: '36575515',
ms_writing: '1680932',
ios_pending: '0',
ms_io: '410844',
ms_weighted_io: '2101936' } ]
[ { Interface: 'wlan0:',
status: '0000',
link: { Quality: '51.' },
level: { Quality: '-59.' },
noise: { Quality: '-256' },
nwid: { 'Discarded packets': '0' },
crypt: { 'Discarded packets': '0' },
frag: { 'Discarded packets': '0' },
retry: { 'Discarded packets': '40' },
misc: { 'Discarded packets': '54' },
beacon: { Missed: '0' } } ]
if(!procfs.works) process.exit('oh no!')
FAQs
get detailed information (more than ps, top etc) about running process on linux machines from node.
The npm package procfs-stats receives a total of 3,099 weekly downloads. As such, procfs-stats popularity was classified as popular.
We found that procfs-stats demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.