Monitor incoming connections of proxies and balancers.

watch -n 1 "/usr/sbin/lsof -p PID |awk '/TCP/{split(\$8,A,\":\"); split(A[2],B,\">\") ; split(B[1],C,\"-\"); print A[1],C[1],B[2], \$9}' | sort | uniq -c"
Maybe this will help you to monitor your load balancers or reverse proxies if you happen to use them. This is useful to discover TIME OUTS and this will let you know if one or more of your application servers is not connected by checking.
Sample Output
Every 1.0s: /usr/sbin/lsof -p 24685 |awk '/TCP/{split($8,A,":"); split(A[2],B,">") ; split(B[1],C,"-"); print A[1],C[1],B[2], $9}' | sort | uniq -c                                                Fri Aug 12 13:58:17 2011

      1 35735 (ESTABLISHED)
      1 54371 (ESTABLISHED)
      1 icl (ESTABLISHED)
      2 icl appcc (ESTABLISHED)
      1 * icl  (LISTEN)

By: ideivid
2011-08-12 19:16:38

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: