forked from digoal/PostgreSQL_HA_with_primary_standby_2vip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_standby_lag.sh
executable file
·31 lines (27 loc) · 1.08 KB
/
check_standby_lag.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
# nagios(/etc/xinetd.d/nrpe)中配置postgres用户调用此脚本
export PGHOME=/opt/pgsql
export LANG=en_US.utf8
export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH
export DATE=`date +"%Y%m%d%H%M"`
export PATH=$PGHOME/bin:$PATH:.
# 配置, node1,node2 可能不一致, 并且需配置.pgpass存储以下密码校验信息
# LAG_MINUTES=3 表示3分钟. 延时超过3分钟则告警.
LOCAL_IP=127.0.0.1
PGUSER=sky_pg_cluster
PGPORT=1921
PGDBNAME=sky_pg_cluster
LAG_MINUTES=3
SQL1="set client_min_messages=warning; select 'standby_in_allowed_lag' as cluster_lag from cluster_status where now()-last_alive < interval '$LAG_MINUTES min';"
# standby lag 在接受范围内的标记, LAG=1 表示正常.
LAG=`echo $SQL1 | psql -h $LOCAL_IP -p $PGPORT -U $PGUSER -d $PGDBNAME -f - | grep -c standby_in_allowed_lag`
if [ $LAG -eq 1 ]; then
exit 0
else
echo -e "standby is laged far $LAG_MINUTES mintues from primary . "
exit 1
fi
exit 1
# Author : Digoal zhou
# Email : [email protected]
# Blog : http://blog.163.com/digoal@126/