473,388 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,388 developers and data experts.

hadr monitor script

. $HOME/sqllib/db2profile

set -x

LD=/dbamon/`whoami`/mon/hadr_stats
mac=`hostname`
DTTM=`date +"%y.%m.%d"`
db=$1
user=`whoami`
#NFCNLST=abc@gmail.com
NFCNLST=abc@gmail.com
rm $LD/state.msg 2>/dev/null
rm $LD/role.msg 2>/dev/null
mkdir -p $LD 2>/dev/null
rm $LD/loggap.$1.$mac.$DTTM.out $LD/hbeatm.$1.$mac.$DTTM.out $LD/time.$1.$mac.$DTTM.out $LD/state.$1.$mac.$DTTM.out $LD/status.$1.$mac.$DTTM.out $LD/buffused.$1.$mac.$DTTM.out $LD/all.$1.$mac.$DTTM.out $LD/db2pd.$1.$mac.$DTTM.out 2>/dev/null

db2pd -d $1 -hadr > $LD/db2pd.$1.$mac.$DTTM.out
cp $LD/db2pd.$1.$mac.$DTTM.out $LD/db2pd.$1.$mac.$DTTM.debug.out ##----Added to dbug the script
if [ $? -eq 0 ]
then
#CHK=`cat $LD/db2pd.$1.$mac.$DTTM.out | grep -i STANDBY_REPLAY_LOG_FILE | awk -F "," {'print $1'}`
CHK=`cat $LD/db2pd.$1.$mac.$DTTM.out | tail -2 | head -1 | awk '{print $1}'`
if [ "$CHK" != "HADR" ]
then
cat $LD/db2pd.$1.$mac.$DTTM.out | grep HADR_LOG_GAP | awk {'print $3'} >> $LD/loggap.$1.$mac.$DTTM.out
cat $LD/db2pd.$1.$mac.$DTTM.out | grep TIME_SINCE_LAST_RECV | awk {'print $3'} >> $LD/hbeatm.$1.$mac.$DTTM.out
cat $LD/db2pd.$1.$mac.$DTTM.out | egrep -i "HADR_ROLE|HADR_STATE" | awk -F "=" {'printf $2'} >> $LD/state.$1.$mac.$DTTM.out
cat $LD/db2pd.$1.$mac.$DTTM.out | grep -i -w "HADR_CONNECT_STATUS" | awk {'print $3'} >> $LD/status.$1.$mac.$DTTM.out
find $LD/ignore.congestion -cmin +10 | while read line
do
rm $line 2>/dev/null
done
cat $LD/status.$1.$mac.$DTTM.out | tr '[:lower:]' '[:upper:]' | read status
if [ $status = "CONGESTED" ]
then
if [ ! -f $LD/ignore.congestion ]
then
mail -s "$mac:`whoami`:$1: Traffic is $status between the HADR pair" abc@gmail.com < $LD/db2pd.$1.$mac.$DTTM.out
touch $LD/ignore.congestion
fi
fi
if [ -f $LD/hadr_stats.$1.$mac.$DTTM.out ]
then
SRVO=`cat $LD/hadr_stats.$1.$mac.$DTTM.out | tail -1 | awk '{print $4}'`
else
file=`ls -lrt $LD/hadr_stats.$1.$mac.*.out | tail -1 | awk '{print $9}'`
SRVO=`cat $file | tail -1 | awk '{print $4}'`
fi
SRV=`cat $LD/db2pd.$1.$mac.$DTTM.out | grep -i HADR_ROLE | awk {'print $3'}`
if [[ $SRVO != $SRV && $status != "DISCONNECTED" && $SRVO != "" ]]
then
echo "Role switch happened for $db. $mac is now the new $SRV" > $LD/role.msg
mail -s "!$mac:$user:$db: HADR Role switch" $NFCNLST < $LD/role.msg
if [ $SRV = "STANDBY" ]
then
db2 connect to $db > /dev/null
db2 -v "force applications all" > $LD/force.apps.$DTTM.out
db2 terminate > /dev/null
fi
fi
if [ $SRV = "STANDBY" ]
then
cat $LD/db2pd.$1.$mac.$DTTM.out | grep -i STANDBY_RECV_BUF_PERCENT| awk -F "=" {'print $2'} >> $LD/buffused.$1.$mac.$DTTM.out
chk=`cat $LD/db2pd.$1.$mac.$DTTM.out | head -2 | tail -1 | awk '{print $8}'`
if [ $chk = "Active" ]
then
cat $LD/db2pd.$1.$mac.$DTTM.out | head -2 | tail -1 | awk '{print $17}' >> $LD/time.$1.$mac.$DTTM.out
else
cat $LD/db2pd.$1.$mac.$DTTM.out | head -2 | tail -1 | awk '{print $16}' >> $LD/time.$1.$mac.$DTTM.out
fi
else
cat $LD/db2pd.$1.$mac.$DTTM.out | head -2 | tail -1 | awk '{print $16}' >> $LD/time.$1.$mac.$DTTM.out
echo "-" >> $LD/buffused.$1.$mac.$DTTM.out
fi
paste $LD/time.$1.$mac.$DTTM.out $LD/loggap.$1.$mac.$DTTM.out $LD/hbeatm.$1.$mac.$DTTM.out $LD/state.$1.$mac.$DTTM.out $LD/status.$1.$mac.$DTTM.out $LD/buffused.$1.$mac.$DTTM.out > $LD/all.$1.$mac.$DTTM.out
if [ $? -eq 0 ]
then
rm $LD/loggap.$1.$mac.$DTTM.out $LD/hbeatm.$1.$mac.$DTTM.out $LD/time.$1.$mac.$DTTM.out $LD/state.$1.$mac.$DTTM.out $LD/status.$1.$mac.$DTTM.out $LD/buffused.$1.$mac.$DTTM.out $LD/db2pd.$1.$mac.$DTTM.out 2>/dev/null
fi

if [ ! -f $LD/hadr_stats.$1.$mac.$DTTM.out ]
then
echo "Timestamp LogGapAvg HeartBeatsMissed Server State Status RcvBuffUsedpct" >> $LD/hadr_stats.$1.$mac.$DTTM.out
fi
cat $LD/all.$1.$mac.$DTTM.out >> $LD/hadr_stats.$1.$mac.$DTTM.out
rm $LD/all.$1.$mac.$DTTM.out 2>/dev/null
elif [ "$CHK" = "HADR" ]
then
echo "HADR is not active on $mac:$user:$db" > $LD/state.msg
mail -s "!$mac:$user:$db: HADR state INACTIVE" $NFCNLST < $LD/state.msg
else
echo "Cannot identify HADR state on $mac:$user:$db" > $LD/state.msg
mail -s "!$mac:$user:$db: HADR state UNKNOWN" $NFCNLST < $LD/state.msg
fi
else
echo "Cannot identify HADR state on $mac:$user:$db as db2pd command is failing" > $LD/state.msg
mail -s "!$mac:$user:$db: HADR state UNKNOWN" $NFCNLST < $LD/state.msg
fi
exit 0
Oct 11 '21 #1
0 5217

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Aaron | last post by:
Is there a script that monitor (ping) my website every hour and run iisreset if it receives an error or no response. Thanks Aaron
1
by: Bruce M | last post by:
Is there a way to run the db2-generated HADR-create script outside of DB2CC beyond the obvious? My DB2CC generates the HADR script and then abends because of a java error meaning I can't finish my...
4
by: bwmiller16 | last post by:
Folks - Again, a three-peat: RH AS3, UDB 8.1.7 on one pair of x-series, 8.1.8 on 2 i86 test boxes... We were just about to put all we had into production and now we're unable to get HADR to...
14
by: michael.bierenfeld | last post by:
Hi, there ..... coming from the Oracle World I am wondering if there is a DB2 command like "set linesize 1000" in SQL*Plus. The DB2 Commandline inserts <CR> after n Characters but I want all...
7
by: Mark A | last post by:
If server 01 running HADR in the primary role crashes, and the DBA does a HADR takeover by force on the 02 server to switch roles, then the 02 server is now the primary. What happens when the...
16
by: gumby | last post by:
I'm having trouble getting HADR to work with the sample databases on two HS20 xSeries blades, Red Hat ES4 up3, DB2 8.2.4, getting the following error. SQL1768N Unable to start HADR. Reason code...
3
by: Laurence | last post by:
Hi folks, Anyone knows what do these mean? Primary log position(file, page, LSN) = S0000009.LOG, 0, 00000000036B0000 Standby log position(file, page, LSN) = S0000008.LOG, 357,...
4
by: madzambonis | last post by:
Here is the situation.... We have Primary Server A linked to Standby Server B via HADR. Primary Server A has recently installed LOGARCHMETH1 to archive logs and a 2nd homegrown script that...
0
by: ebusiness | last post by:
Hi, I setup an event monitor to monitor transaction execution time in HADR (SYNC mode) environment. Could anybody tell me the value returned from the monitor is only the execution time in...
3
by: deshaipet | last post by:
db2level = V97 FP 2. Oslevel = AIX 6.1 TL 03. TSAMP level = 3.1 FP 06 Hi, In todays world we have TSAMP HADR monitoring scripts which monitoring scripts to monitor failures in HADR system....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.