postgresql_replication_monitor
This is an old revision of the document!
postgresql replication monitor
############################# # Requirement Specification ############################# # - It require `bc` # - Only monitor streaming replication status ############################ ## Define Custom Variables ############################ ## Define Nagios utils LIBEXEC="/usr/lib64/nagios/plugins" . $LIBEXEC/utils.sh ## Exit Codes STATE_OK=0 STATE_WARNING=1 STATE_CRITICAL=2 STATE_UNKNOWN=3 ## Primary Server Information export p_host=127.0.0.1 export p_port=5436 ## Secondary Server Information (generally not used unless you have diff. port) ## In case of diff. port please change resules in codes section. export s_host=localhost export s_port=5432 ## Psql / bc Location export psql=/usr/local/pg-9.0.3/bin/psql export bc=/usr/bin/bc ## Results in codes prime_num=$($psql -t -c "SELECT pg_current_xlog_location()" -h$p_host -p$p_port) sec_num=$($psql -t -c "select pg_last_xlog_receive_location()") thr_num=$($psql -t -c "select pg_last_xlog_replay_location()") pr_num=$(echo $prime_num | awk -F / '{print $2}') sr_num=$(echo $sec_num | awk -F / '{print $2}') tr_num=$(echo $thr_num | awk -F / '{print $2}') pr_int_num=$(echo "ibase=16; $pr_num" | $bc) sr_int_num=$(echo "ibase=16; $sr_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" ########################### ## Customization End here ########################### 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" exit $STATE_OK else if [[ $pr_int_num -eq $sr_int_num ]] ; then if [[ $pr_int_num -ne $tr_int_num ]] ; then echo "Stream: Primary: $pr_int_num Secondary: $sr_int_num Import: $tr_int_num : WARNING" exit $STATE_WARNING fi else echo "Stream: Primary: $pr_int_num Secondary: $sr_int_num Import: $tr_int_num : CRITICAL" #echo "pgprod2.mcfina.com;$pr_int_num;$sr_int_num;$tr_int_num;1;WARNING" #echo "WARNING - Stream is behind" exit $STATE_CRITICAL fi echo "Stream: Primary: $pr_int_num Secondary: $sr_int_num Import: $tr_int_num : UNKNOWN" exit $STATE_UNKNOWN fi
postgresql_replication_monitor.1310480310.txt.gz · Last modified: 2020/08/10 02:29 (external edit)