473,287 Members | 1,663 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,287 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 5211

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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.