-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chuek,

Caldarale, Charles R wrote:
>> From: keeplearning [mailto:[EMAIL PROTECTED]
>> Subject: Thread Dumps/ Emailing Results...
>>
>> So, do i need to supply process id with this command. Like:
>> kill -3 <process id>.
> 
> That's one way to do it.  My preference is to use the jstack tool from the 
> JDK, assuming you're running a 1.5 or 1.6 Sun JVM.

I have written a script to check for OOMs by checking catalina.out for
"OutOfMemoryError". When such an error is detected, I run the following
commands (apologies for the line wrapping):

APP_PID=[fill this in with a way to get your app's pid]
  # Make sure the pid looks like a pid
  if [ "${APP_PID}" != `expr match "${APP_PID}" '\([0-9]\+\)'` ] ; then
    echo "Could not determine the correct pid for ${APP_NAME}" >> ${OUTPUT}
  else
    # Make sure that this pid belongs to the proper process
    ps -e x | grep "^[ \t]*${APP_PID}.*${PROCESS_STRING}" > /dev/null

    if [ "$?" == "0" ] ; then
      # This is the correct pid

      if [ -x ${JSTACK} ] ; then
         # jstack is available on the system: this is way easier

         echo '=============== THREAD DUMP =================' >> ${OUTPUT}
         ${JSTACK} ${APP_PID} >> "${OUTPUT}" 2>&1
      else
         # Generate a thread dump on the java process
         kill -QUIT ${APP_PID}

         # Now, go find that thread dump in the log file
         echo '=============== THREAD DUMP =================' >> ${OUTPUT}
         dump_start_line=`grep -n '^Full thread' ${LOGFILE} | tail -n 1
| sed -e
 's/\([0-9]\+\):.*/\1/'`
         tail -n +${dump_start_line} ${LOGFILE} >> ${OUTPUT}
      fi

      # What the heck, let's get a heap dump, too.
      echo '================ HEAP SUMMARY ===================' >> ${OUTPUT}
      ${JMAP} -heap ${APP_PID} >> ${OUTPUT} 2>&1

      echo '================ OBJECT HISTOGRAM ===============' >> ${OUTPUT}
      ${JMAP} -histo ${APP_PID} >> ${OUTPUT} 2>&1
    else
      echo 'Could not determine the correct pid for ${APP_NAME}' >>
${OUTPUT}
    fi
  fi

  mail -s "Found OOME in ${APP_NAME}!" ${ADMIN_EMAIL} < ${OUTPUT}

####

If jstack isn't available, we use a hack to generate a thread dump and
extract it from catalina.out.

> You still need the process id, and the JDK includes the jps tool
> which is easier than wading through the output of ps.  The JDK tools
> also work on Windows, whereas kill doesn't normally exist there.

Yes, this is a UNIX-specific script, unless you want to run it on Cygwin
(untested, by the way). But, if you're running on Windows, you don't
really care about uptime, anyway, do you? ;)

Hope that helps,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEUEARECAAYFAkkQwkMACgkQ9CaO5/Lv0PB2vgCYvDQJNbkkVEFcpL/QnEegGg6x
iQCgmpuTbVPR6THyGbXE0U8GTLEK/No=
=Kg1V
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to