Categories
Tips

How to Find Out the Number of Files Opened by Tomcat Hosted Application

When working with Spring Data for file  based integration, I was wondering how the application is handling the file processing.  We have seen file descriptors left opened after the application run for a while. and the application eventually stalled because an IO Exception being through out for the files opened by the application have reached its maximum.

The following script help me to monitor the file descriptor opened in the Linux server:

#!/bin/sh
#
#published GNU GPL3.0
#please change /foo/bar to the folder you want to mornitor
PID=`ps -eaf | grep tomcat | grep -v grep |grep org.apache.catalina.startup.Bootstrap | awk '{print $2}'`
if [[ "" != "$PID" ]]; then
DATE=`date '+%Y-%m-%d %H:%M:%S'`
echo "PID $PID $DATE">>lsof.log
/usr/sbin/lsof -a -p $PID|grep /foo/bar >>lsof.log
fi

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.