Monitor Tomcat with Monit

Discussion in 'Server Operation' started by domino, Dec 13, 2007.

  1. domino

    domino New Member

    Hi and Happy Holidays!

    I have a server currently running Apache Tomcat. It often crashes when the connections go over 40. The previous admin created a script that restarts apache and tomcat when it hits 40 connections. I was wondering if it's possible to to the same thing with Monit.

    Here is the current cron script that runs every minute:

    source /etc/profile
    RESDATE=`date "+DATE: %m/%d/%y TIME: %H:%M:%S"`
    USER=`netstat -tunlap | grep ESTABLISHED | grep -v sshd | grep -v '' | wc -l`
    if [ "$USER" -gt 40 ] || [ "$USER" = 0 ]
    echo " SERVER RESTART @ $RESDATE" >> /root/scripts/RESTARTS.TXT
    service httpd stop;/usr/local/tomcat/bin/;sleep 5;/usr/local/tomcat/bin/;service httpd start
    cat /dev/null
    Is there a way to get Monit to do the same thing with the above script?

    Last edited: Dec 13, 2007
  2. falko

    falko Super Moderator ISPConfig Developer

  3. domino

    domino New Member

    Thanks for the reply. We've adjusted some things on the java app side that keeps apache tomcat from crashing. We have noticed that now when connection go over 40, the server goes to a crawl. I'm thinking that the connections aren't flushing or not being released. We don't need to recode the application because we are dropping tomcat in a few months and moving to ruby and rails. So for the time being, I just need monit to restart apache tomcat whenever it hits 40 connections.

    The script above lets us track how many times the servers are being restarted. Manually logging it doesn't make sense. I would rather have a system like monit and munin/cacti. It's just pretty slim on finding things on managing apache tomcat with monit.

Share This Page