User Tools

Site Tools


postgresql_replication_monitor

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
postgresql_replication_monitor [2011/07/12 10:18]
k2patel created
postgresql_replication_monitor [2012/04/13 11:47]
k2patel
Line 2: Line 2:
  
 <code bash> <code bash>
 +#!/bin/bash
 +# ---------------
 +#< By k2patel >
 +# ---------------- ​
 +#        \   ^__^
 +#         ​\ ​ (oo)\_______
 +#            (__)\       )\/\
 +#                ||----w |
 +#                ||     ||
 +#
 #############################​ #############################​
 # Requirement Specification # Requirement Specification
Line 33: Line 43:
  
 ## Psql / bc Location ## Psql / bc Location
-export psql=/usr/local/pg-9.0.3/bin/psql+export psql=/usr/pgsql-9.0/​bin/​psql
 export bc=/​usr/​bin/​bc export bc=/​usr/​bin/​bc
 +
 +## Delay Limit
 +export dlylmt=1000000
 +export wrnlmt=100000
 +
 +
 +###########################​
 +## Customization End here
 +###########################​
  
  
 ## Results in codes ## Results in codes
-prime_num=$($psql -t -c "​SELECT pg_current_xlog_location()"​ -h$p_host -p$p_port) +prime_num=$($psql ​-U postgres ​-t -c "​SELECT pg_current_xlog_location()"​ -h$p_host -p$p_port) 
-sec_num=$($psql -t -c "​select pg_last_xlog_receive_location()"​) +sec_num=$($psql ​-U postgres ​-t -c "​select pg_last_xlog_receive_location()" ​-h$s_host -p$s_port
-thr_num=$($psql -t -c "​select pg_last_xlog_replay_location()"​)+thr_num=$($psql ​-U postgres ​-t -c "​select pg_last_xlog_replay_location()" ​-h$s_host -p$s_port)
  
 pr_num=$(echo $prime_num | awk -F / '​{print $2}') pr_num=$(echo $prime_num | awk -F / '​{print $2}')
 sr_num=$(echo $sec_num | awk -F / '​{print $2}') sr_num=$(echo $sec_num | awk -F / '​{print $2}')
 tr_num=$(echo $thr_num | awk -F / '​{print $2}') tr_num=$(echo $thr_num | awk -F / '​{print $2}')
 +#​sr_num=7AE0EE48
  
 pr_int_num=$(echo "​ibase=16;​ $pr_num"​ | $bc) pr_int_num=$(echo "​ibase=16;​ $pr_num"​ | $bc)
Line 50: Line 70:
 tr_int_num=$(echo "​ibase=16;​ $tr_num"​ | $bc) tr_int_num=$(echo "​ibase=16;​ $tr_num"​ | $bc)
  
-echo "Prime $pr_int_num"​ 
-echo "Secon $sr_int_num"​ 
-echo "thrir $tr_int_num"​ 
  
-###########################​ +#echo "Prime $pr_int_num"​ 
-## Customization End here +#echo "Secon $sr_int_num"​ 
-###########################​+#echo "thrir $tr_int_num"​
  
 +
 +if [[ $pr_int_num -eq ''​ || $sr_int_num -eq ''​ || $tr_int_num -eq ''​ ]]; then
 +        echo "​Stream Has no Value to compare : CRITICAL"​
 +        exit $STATE_CRITICAL
 +else
 if [[ $pr_int_num -eq $sr_int_num && $pr_int_num -eq $tr_int_num && $sr_int_num -eq $tr_int_num ]] ; then if [[ $pr_int_num -eq $sr_int_num && $pr_int_num -eq $tr_int_num && $sr_int_num -eq $tr_int_num ]] ; then
         echo "​Stream:​ Primary: $pr_int_num Secondary: $sr_int_num Import: $tr_int_num : OK"         echo "​Stream:​ Primary: $pr_int_num Secondary: $sr_int_num Import: $tr_int_num : OK"
Line 64: Line 86:
         if [[ $pr_int_num -eq $sr_int_num ]] ; then         if [[ $pr_int_num -eq $sr_int_num ]] ; then
                 if [[ $pr_int_num -ne $tr_int_num ]] ; then                 if [[ $pr_int_num -ne $tr_int_num ]] ; then
 +                if [ $(bc <<<​ $pr_int_num-$sr_int_num) -lt $wrnlmt ]; then
 +                echo "​Stream:​ Primary: $pr_int_num Secondary: $sr_int_num Import: $tr_int_num : BEHIND : OK"
 +                exit $STATE_OK
 +                else
                 echo "​Stream:​ Primary: $pr_int_num Secondary: $sr_int_num Import: $tr_int_num : WARNING"​                 echo "​Stream:​ Primary: $pr_int_num Secondary: $sr_int_num Import: $tr_int_num : WARNING"​
                 exit $STATE_WARNING                 exit $STATE_WARNING
 +                fi
                 fi                 fi
         else         else
 +#               echo $(bc <<<​ $pr_int_num-$sr_int_num)
 +                if [ $(bc <<<​ $pr_int_num-$sr_int_num) -gt $dlylmt ]; then
                 echo "​Stream:​ Primary: $pr_int_num Secondary: $sr_int_num Import: $tr_int_num : CRITICAL"​                 echo "​Stream:​ Primary: $pr_int_num Secondary: $sr_int_num Import: $tr_int_num : CRITICAL"​
 +                exit $STATE_CRITICAL
 +                else
 +                if [ $(bc <<<​ $pr_int_num-$sr_int_num) -lt $wrnlmt ]; then
 +                echo "​Stream:​ Primary: $pr_int_num Secondary: $sr_int_num Import: $tr_int_num : BEHIND : OK"
 +                exit $STATE_OK
 +                else
 +                echo "​Stream:​ Primary: $pr_int_num Secondary: $sr_int_num Import: $tr_int_num : WARNING"​
                 #echo "​pgprod2.mcfina.com;​$pr_int_num;​$sr_int_num;​$tr_int_num;​1;​WARNING"​                 #echo "​pgprod2.mcfina.com;​$pr_int_num;​$sr_int_num;​$tr_int_num;​1;​WARNING"​
                 #echo "​WARNING - Stream is behind"​                 #echo "​WARNING - Stream is behind"​
-                exit $STATE_CRITICAL+                exit $STATE_WARNING 
 +                fi 
 +                fi
         fi         fi
         echo "​Stream:​ Primary: $pr_int_num Secondary: $sr_int_num Import: $tr_int_num : UNKNOWN"​         echo "​Stream:​ Primary: $pr_int_num Secondary: $sr_int_num Import: $tr_int_num : UNKNOWN"​
         exit $STATE_UNKNOWN         exit $STATE_UNKNOWN
 fi fi
 +
 +fi
 +
 </​code>​ </​code>​
postgresql_replication_monitor.txt · Last modified: 2012/04/13 11:47 by k2patel