Google
 
Web unafbapune.blogspot.com

Thursday, October 27, 2011

 

Scriptfu counting opened file descriptors

How to count the number of opened file descriptors of all running JVM's on a Linux host ?

for ((;;))
do
declare sum=0
for i in `pgrep -lf jdk | awk '{print $1}'`
do
((sum += `sudo /usr/sbin/lsof -p $i | wc -l`))
done
echo "`date` java: $sum"
sleep 5
done | tee fd-java.log

Or a faster alternative:
for ((;;))
do
for i in `pgrep -lf jdk | awk '{print $1}'`
do
s="$s$i,"
done
echo "`date` java: `sudo /usr/sbin/lsof -p $s | wc -l`"
sleep 5
done | tee fd-java.log

What if you need a break down per JVM ?
for ((;;))
do
echo -n "`date` "
for i in `pgrep -lf jdk | awk '{print $1}'`
do
echo -n "[$i]:"
sudo /usr/sbin/lsof -p $i | wc -l | tr '\n' ','
echo -n " "
done
echo ""
sleep 5
done | tee fd-jvms.log

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?