监控分析tomcat日志

apache下面四个tomcat,监控tomcat的catalina.log是否出现ERROR等。

#!/bin/sh

#set -x
#SYS_TIME=date +"%Y-%m-%d %H:%M"
TOMCAT1_LOG="/home/tomcat01/logs/catalina.out"
TOMCAT2_LOG="/home/tomcat02/logs/catalina.out"
TOMCAT3_LOG="/home/tomcat03/logs/catalina.out"
TOMCAT4_LOG="/home/tomcat04/logs/catalina.out"

RUNNING_LOG="/home/tomcatlog/running.log"
ERROR_LOG="/home/tomcatlog/54error.log"
TEMPLOG="/home/tomcatlog/templog.log"
KEYWORLD="/home/tomcatlog/keyworld.conf"

#########Program start############
for LOGFILE in "$TOMCAT1_LOG" "$TOMCAT2_LOG" "$TOMCAT3_LOG" "$TOMCAT4_LOG"
        do
                LOG_STATUS_TIME=`stat -c %y $LOGFILE |awk -F '.' '{print $1}'`
                END_TIME=`date -d "$LOG_STATUS_TIME" +"%Y-%m-%d %H:%M"`

                for ((i=300;i>=0;i=i-60))
                        do
                                START_TIME=`date -d "$LOG_STATUS_TIME" +%s|awk -v second="$i" '{print strftime("%Y-%m-%d %H:%M",$0-second)}'`
                                grep -a "${START_TIME}" $LOGFILE > /dev/null
                                if [ $? == 0 ]
                                then
                                        break
                                fi
                        done
#               echo $LOG_STATUS_TIME
#               echo $LOGFILE
#               echo $START_TIME
#               echo $END_TIME
                START_LINE=`sed -n "/$START_TIME/=" $LOGFILE | head -n1`
                END_LINE=`sed -n "/$END_TIME/=" $LOGFILE | tail -n1`
                echo $START_LINE
                echo $END_LINE

                sed -n "${START_LINE},${END_LINE}p" $LOGFILE > $TEMPLOG
                while read keyworld
                do
                        world=$(echo ${keyworld} | awk '{print $2}')
                        while read templog
                        do
                                worldinfo=$(echo ${templog}| grep ${world} | grep -v grep)
                                if [  -z "${worldinfo}" ]
                                then
                        #               echo "`date` $LOGFILE OK" > /dev/null
                                else
                                        LogContent1=$(echo ${templog})
                                        echo "$LogContent1 ${world} find in $LOGFILE" >> $ERROR_LOG
                                fi
                        done < $TEMPLOG
                done < $KEYWORLD
        done

ftp -i -n  192.168.XX。XXX < user XXX  XXX
lcd /home/tomcatlog/
cd abc
binary
put 54error.log
bye
!

=====================================================================

keyworld.conf 内容

vi keyworld.conf
1 ERROR





本文转自 vfast_chenxy 51CTO博客,原文链接:http://blog.51cto.com/chenxy/801628,如需转载请自行联系原作者

你可能感兴趣的:(监控分析tomcat日志)