Skip to content

Instantly share code, notes, and snippets.

@blak3r
Created March 4, 2014 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blak3r/d470a4254059acca926a to your computer and use it in GitHub Desktop.
Save blak3r/d470a4254059acca926a to your computer and use it in GitHub Desktop.
Output the number of files used by several processes to the command line every 5 seconds.
while true; do
TIMESTAMP=`date "+%Y-%m-%d %H:%M:%S"`
x1=`ps aux | grep "[v]ar.www.bin.asteriskPhoneEventProducer.js" | pcregrep -o1 "^root\s+(\d+)\s"`
x2=`ps aux | grep "[v]ar.www.bin.phoneEventProcessor.js" | pcregrep -o1 "^root\s+(\d+)\s"`
x3=`ps aux | grep "[v]ar.www.bin.phoneEventCoordinator.js" | pcregrep -o1 "^root\s+(\d+)\s"`
x4=`ps aux | grep "[v]ar.www.bin.app.js" | pcregrep -o1 "^root\s+(\d+)\s"`
x5=`ps aux | grep "[v]ar.www.bin.http.phone.event.producer.js" | pcregrep -o1 "^root\s+(\d+)\s"`
all=`lsof -i -n -P | grep "nodejs" | wc -l`
c1=`lsof -i -n -P | grep "nodejs.*$x1" | wc -l`
c2=`lsof -i -n -P | grep "nodejs.*$x2" | wc -l`
c3=`lsof -i -n -P | grep "nodejs.*$x3" | wc -l`
c4=`lsof -i -n -P | grep "nodejs.*$x4" | wc -l`
c5=`lsof -i -n -P | grep "nodejs.*$x5" | wc -l`
echo "$TIMESTAMP -- Total: $all AstFor: $c1 Producer0: $c2 Coord: $c3 App: $c4 HttpEv: $c5"
sleep 5
done
@blak3r
Copy link
Author

blak3r commented Mar 4, 2014

Created to monitor which of my node processes was leaking sockets over time...

Output looks like this:
Just edit the name of processes asteriskPhoneEventProducer, and potentially set root to the name of the user that runs the process.

2014-03-04 09:14:47 -- Total: 136  AstFor: 27  Producer0: 7  Coord: 72  App: 136   HttpEv: 8
2014-03-04 09:14:53 -- Total: 136  AstFor: 27  Producer0: 7  Coord: 72  App: 134   HttpEv: 8
2014-03-04 09:14:58 -- Total: 136  AstFor: 27  Producer0: 7  Coord: 72  App: 136   HttpEv: 8
2014-03-04 09:15:04 -- Total: 136  AstFor: 27  Producer0: 7  Coord: 72  App: 136   HttpEv: 8
2014-03-04 09:15:09 -- Total: 130  AstFor: 27  Producer0: 7  Coord: 72  App: 131   HttpEv: 8
2014-03-04 09:15:15 -- Total: 130  AstFor: 27  Producer0: 7  Coord: 69  App: 130   HttpEv: 8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment