forked from zhangnq/nagios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_pgbouncer.sh
62 lines (49 loc) · 2.13 KB
/
check_pgbouncer.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
#define status
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
res=`/opt/PostgreSQL/9.2/bin/psql -U postgres -p 5432 -d pgbouncer -A -t -c "show pools"`
conns=0
cl_waitings=0
cl_actives=0
req=0
pg_in=0
pg_out=0
for line in $res
do
conn=`echo $line |awk -F '|' '{print $3}' `
cl_waiting=`echo $line |awk -F '|' '{print $4}' `
let conns=$conn+$conns
let cl_waitings=$cl_waiting+$cl_waitings
let cl_actives=$conn+$cl_actives
done
let conns=$conns+$cl_waitings
max_conn=`grep "max_client_conn" /etc/pgbouncer/pgbouncer.ini |awk '{print $NF}'`
w_conn=`echo "$max_conn*0.8"|bc`
c_conn=`echo "$max_conn*0.95"|bc`
w_conn=`echo ${w_conn%.*}`
c_conn=`echo ${c_conn%.*}`
left=`tail /var/log/pgbouncer/pgbouncer.log |grep -c "LOG Stats:.*req/s"`
if [ $left -ne 0 ];then
req=`tail /var/log/pgbouncer/pgbouncer.log |grep "LOG Stats:.*req/s" |tail -n 1 |awk '{print $6}'`
pg_in=`tail /var/log/pgbouncer/pgbouncer.log |grep "LOG Stats:.*req/s" |tail -n 1 |awk '{print $9}'`
pg_out=`tail /var/log/pgbouncer/pgbouncer.log |grep "LOG Stats:.*req/s" |tail -n 1 |awk '{print $12}'`
pg_in=`echo "$pg_in/1024"|bc`
pg_out=`echo "$pg_out/1024"|bc`
fi
if [ $conns -gt $w_conn -o $req -lt 600 ];then
echo "WARNING - max_conn=$max_conn,conns=$conns,req=$req,cl_waiting=$cl_waitings,cl_active=$cl_actives,in=$pg_in,out=$pg_out | conn=$conns;$w_conn;$c_conn;;req=$req;600;300;;"
exit $STATE_WARNING
fi
if [ $conns -gt $c_conn -o $req -lt 300 ];then
echo "CRITICAL - max_conn=$max_conn,conns=$conns,req=$req,cl_waiting=$cl_waitings,cl_active=$cl_actives,in=$pg_in,out=$pg_out | conn=$conns;$w_conn;$c_conn;;req=$req;600;300;;"
exit $STATE_CRITICAL
fi
a=`tail /var/log/pgbouncer/pgbouncer.log |grep -c "LOG Stats"`
if [ $a -lt 1 ];then
echo "WARNING - Please check pgbouncer stats!"
exit $STATE_WARNING
fi
echo "OK - It's ok! max_conn=$max_conn,conns=$conns,req=$req,cl_waiting=$cl_waitings,cl_active=$cl_actives,in=$pg_in,out=$pg_out | conn=$conns;$w_conn;$c_conn;;req=$req;600;300;;"
exit $STATE_OK