Zahid_Haseeb
10 years agoModerator
Echo message (Request/Response) Monitor
Environment
OS = Linux 6x/7x
SFHA = Suppose latest i.e 6x
Query:
We have a two nodes local HA. A customized application running on it(HA) fine. The customized application send a tcp echo response (800) on the tcp echo request of (810) from a machine exist on LAN. I want to monitor this echo cycle under HA.
Try the following:
MAX_TIME=300 # 5 mins LOGFILE=/tmp/testlog ARG=$2 LOCKFILE=/tmp/.$2.DO_NOT_REMOVE case "$1" in start) # START APP touch $LOCKFILE ;; stop) # Stop App rm $LOCKFILE ;; monitor) if [ -a $LOCKFILE ] then # Check date in LOGFILE is less than MAX_TIME ago logdate_str=`/usr/bin/tail -1 $LOGFILE | /bin/awk ' {split($1,slash,"/");print slash[3]"/"slash[2]"/"slash[1]" "$2}'` logdate_epoch=`/bin/date -d "$logdate_str" +%s` today_epoch=`/bin/date +%s` (( sec_since_log=$today_epoch - $logdate_epoch )) if [[ $sec_since_log -gt $MAX_TIME ]] then # More than max_time so return offline rm $LOCKFILE exit 100 else exit 110 fi else exit 100 fi ;; *) echo "Usage: $0 {start|stop|monitor} resource_name" exit 1 ;; esacMike
Try this:
MAX_TIME=300 # 5 mins ARG=$2 AWK=/bin/awk TAIL=/bin/tail DATE=/bin/date LOCKFILE=/tmp/.$2.DO_NOT_REMOVE case "$1" in start) # START APP touch $LOCKFILE ;; stop) # Stop App rm $LOCKFILE ;; monitor) if [ -a $LOCKFILE ] then LOGFILE=/tmp/Z35xlo.o`$DATE +%m%d` # Check date in LOGFILE is less than MAX_TIME ago logdate_str=`$TAIL -1 $LOGFILE | $AWK -F: '{print "20"$2":"$3":"$4}'` logdate_epoch=`$DATE -d "$logdate_str" +%s` today_epoch=`$DATE +%s` (( sec_since_log=$today_epoch - $logdate_epoch )) # echo "DEBUG: $today_epoch, $logdate_str, $logdate_epoch" if [[ $sec_since_log -gt $MAX_TIME ]] then # More than max_time so return offline rm $LOCKFILE exit 100 else exit 110 fi else exit 100 fi ;; *) echo "Usage: $0 {start|stop|monitor} resource_name" exit 1 ;; esacMike

