#!/bin/csh
###################################################
# QA GIN Monitor
# Erez Ben Simon
# 14/12/2000
###################################################

set CPUSIZE = "10"
set MEMORYSIZE = "5000"
set CPUSIZE = "60"
clear

xterm -e tail -f /usr/local/apache/logs/access_log &
#xterm -e tail -f /usr/local/gwa/logs/zax.log
#xterm -e tail -f /usr/local/gwa/logs/pici.log

while (1)
        clear
        ########################## PDD ########################################

        set CHKPDD = `ps -a |  grep pdd | awk '{print ($1)}'`
        set CHEKPDDCPU = `top -d 1 | grep pdd | awk '{$10 = substr ($10,0,2); print($10)}'`
        set CHEKPDDMEMORY = `top -d 1 | grep pdd | awk '{$6= substr ($6, 0, length($6)-1 ); print ($6) }'`
        # IS alive?
        if (  "$CHKPDD" == "" ) then
           clear
	   echo -------------------------------------------- >> monitor.log
           date >> monitor.log
           echo "> PDD is down - " >> monitor.log
           echo  ================================================
	   echo  ALERT ! PDD IS DOWN !
           echo  ================================================
           sleep 2
        else
        #CPU size
         if (  "$CHEKPDDCPU" > "$CPUSIZE" ) then
           clear
	   echo -------------------------------------------- >> monitor.log
           date >> monitor.log
           echo "> PDD CPU is $CHEKPDDCPU % - " >> monitor.log
           echo  ================================================
           echo  ALERT ! PDD CPU IS: $CHEKPDDCPU%
           echo  ================================================
           sleep 2
        endif
        #Memory Size
           if (  "$CHEKPDDMEMORY" > "$MEMORYSIZE" ) then
           clear
	   echo -------------------------------------------- >> monitor.log
           date >> monitor.log
           echo "PDD Memory size is $CHEKSPDDMEMORY - " >> monitor.log
           echo  ================================================
           echo  ALERT ! PDD Memory size IS: $MEMORYSIZE
           echo  ================================================
           sleep 2
        endif
      endif

        ################################# SDAD ##################################

        set CHKSDAD =   `ps -a |grep sdad | awk '{print ($1)}'`
        set tmp = `top -d 1 | grep sdad | awk '{$10 = substr ($10,0,1); print($10)}'`
        set CHEKSDADCPU = `top -d 1 | grep sdad | awk '{$10 = substr ($10,0,2); print($10)}'`
        set CHEKSDADMEMORY = `top -d 1 | grep sdad | awk '{$6= substr ($6, 0, length($6)-1 ); print ($6) }'`

        #Is Alive ?
        if (  "$CHKSDAD" == "" ) then
           clear
	   echo -------------------------------------------- >> monitor.log
           date >> monitor.log
           echo "> SDAD is down - " >> monitor.log
           echo  ================================================
           echo  ALERT ! SDAD IS DOWN !
           echo  ================================================
           sleep 2
        else
              #CPU size
                if (  "$CHEKSDADCPU" > "$CPUSIZE" ) then
                   clear
                   echo -------------------------------------------- >> monitor.log
                   date >> monitor.log
                   echo "SDAD CPU is $CHEKSDADCPU % - " >> monitor.log
                   echo  ================================================
                   echo  ALERT ! SDAD CPU IS: $CHEKSDADCPU %
                   echo ================================================
                   sleep 3
               endif


                #Memory Size
              if (  "$CHEKSDADMEMORY" > "$MEMORYSIZE" ) then
                clear
                echo -------------------------------------------- >> monitor.log
                date >> monitor.log
                echo "PDD Memory size is $CHEKSDADMEMORY - " >> monitor.log
                echo  ================================================
                echo  ALERT ! SDAD Memory size IS: $CHEKSDADMEMORY
                echo  ================================================
                sleep 3
              endif
      endif
        #################################HTTPD######################################

        set CHKHTTPD =  `ps -a |  grep httpd | awk '{print ($1)}'`
        set tmp = `top -d 1 | grep httpd | awk '{$10 = substr ($10,0,1); print($10)}'`
        set CHEKHTTPDCPU = `top -d 1 | grep httpd | awk '{$10 = substr ($10,0,2); print($10)}'`
        set CHEKHTTPDMEMORY = `top -d 1 | grep httpd | awk '{$6= substr ($6, 0, length($6)-1 ); print ($6) }'`

        #Is Alive ?
        if (  "$CHKHTTPD" == "" ) then
           ##clear
	   echo -------------------------------------------- >> monitor.log
           date >> monitor.log
           echo "> HTTPD is down - " >> monitor.log
           echo  ================================================
           echo  ALERT ! HTTPD IS DOWN !
           echo  ================================================

	   sleep 3
        else

                #CPU size
                if (  "$CHEKHTTPDCPU" > "$CPUSIZE" ) then
                 clear
                 echo -------------------------------------------- >> monitor.log
                 date >> monitor.log
                 echo "HTTPD CPU is $CHEKHTTPDCPU % - " >> monitor.log
                 echo  ================================================
                 echo  ALERT ! HTTPD CPU IS $CHEKHTTPDCPU
                 echo  ================================================
                 sleep 3
                endif

                #Memory Size
                if (  "$CHEKHTTPDMEMORY" > "$MEMORYSIZE" ) then
                 clear
                 echo -------------------------------------------- >> monitor.log
                 date >> monitor.log
                 echo "HTTPD Memory size is $CHEKHTTPDMEMORY - " >> monitor.log
                 echo  ================================================
                 echo  ALERT ! HTTPD Memory size IS: $MEMORYSIZE
                 echo  ================================================
                 sleep 3
                endif

        endif
       #################################REAL######################################

        set CHKRM =  `ps -a |  grep rmserver | awk '{print ($1)}'`
        set tmp = `top -d 1 | grep rmserver | awk '{$10 = substr ($10,0,1); print($10)}'`
        set CHEKRMCPU = `top -d 1 | grep rmserver | awk '{$10 = substr ($10,0,2); print($10)}'`
        set CHEKRMMEMORY = `top -d 1 | grep rmserver | awk '{$6= substr ($6, 0, length($6)-1 ); print ($6) }'`

        #Is Alive ?
        if (  "$CHKRM" == "" ) then
           clear
	   echo -------------------------------------------- >> monitor.log
           date >> monitor.log
           echo "> HTTPD is down - " >> monitor.log
           echo  ================================================
           echo  ALERT ! Real IS DOWN !
           echo  ================================================
           sleep 3
        else

                #CPU size
                if (  "$CHEKRMCPU" > "$CPUSIZE" ) then
                 clear
                 echo -------------------------------------------- >> monitor.log
                 date >> monitor.log
                 echo "HTTPD CPU is $CHEKHTTPDCPU % - " >> monitor.log
                 echo  ================================================
                 echo  ALERT ! Real Server CPU IS $CHEKHTTPDCPU
                 echo  ================================================
                 sleep 3
                endif

                #Memory Size
                if (  "$CHEKRMMEMORY" > "$MEMORYSIZE" ) then
                  clear
                  echo -------------------------------------------- >> monitor.log
                  date >> monitor.log
                  echo "HTTPD Memory size is $CHEKHTTPDMEMORY - " >> monitor.log
                  echo  ================================================
                  echo  ALERT ! Real Server Memory size IS: $MEMORYSIZE
                  echo  ================================================
                  sleep 3
                endif
          endif

        echo "-------------- Real Server -------------------------------"
        ps -ef |  grep rmserver   | awk '{print("PID:" $2" " $3 " TIME: " $5 )}'
        echo "--------------  PDD --------------------------------------"
        ps -ef |  grep pdd   | awk '{print("PID:" $2" " $3 " TIME: " $5 )}'
        echo "-------------- SDAD --------------------------------------"
        ps -ef |  grep sdad   | awk '{print("PID:" $2" " $3 " TIME: " $5 )}'
        echo "-------------- HTTPD -------------------------------------"
        ps -ef |  grep httpd   | awk '{print("PID:" $2" " $3 " TIME: " $5 )}'
        sleep 10
end








