User Tools

Site Tools


postgresql_replication_monitor

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
postgresql_replication_monitor [2011/07/12 16:22] k2patelpostgresql_replication_monitor [2020/08/10 02:35] (current) – external edit 127.0.0.1
Line 3: Line 3:
 <code bash> <code bash>
 #!/bin/bash #!/bin/bash
 +# ---------------
 +#< By k2patel >
 +# ---------------- 
 +#        \   ^__^
 +#          (oo)\_______
 +#            (__)\       )\/\
 +#                ||----w |
 +#                ||     ||
 +#
 ############################# #############################
 # Requirement Specification # Requirement Specification
Line 34: 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 ## Delay Limit
-export dlylmt=100000+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 54: 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 69: 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
-                if [[ $(bc <<< $pr_int_num-$sr_int_num) -gt $dlylmt ]]; then+#               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                 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                 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"
 +                #echo "pgprod2.mcfina.com;$pr_int_num;$sr_int_num;$tr_int_num;1;WARNING"
 +                #echo "WARNING - Stream is behind"
                 exit $STATE_WARNING                 exit $STATE_WARNING
 +                fi
                 fi                 fi
         fi         fi
Line 84: Line 114:
         exit $STATE_UNKNOWN         exit $STATE_UNKNOWN
 fi fi
 +
 +fi
 +
 </code> </code>
postgresql_replication_monitor.1310487741.txt.gz · Last modified: 2020/08/10 02:29 (external edit)