-
Notifications
You must be signed in to change notification settings - Fork 10
/
pgbouncer.sh
43 lines (36 loc) · 1.39 KB
/
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
#!/bin/sh
PGBOUNCER_HOST=$(head -n 1 ~zabbix/.pgpass |cut -d: -f1)
PGBOUNCER_PORT=$(head -n 1 ~zabbix/.pgpass |cut -d: -f2)
MON_USER=$(head -n 1 ~zabbix/.pgpass |cut -d: -f4)
COMMAND=$1
#USER=$3
#DB=$2
if [ "x$COMMAND" = "xdiscover" ]
then
# discovery bases and users
psql -h $PGBOUNCER_HOST -p $PGBOUNCER_PORT -U $MON_USER pgbouncer -t -c 'show pools;' \
| awk -F'|' 'BEGIN { printf "{\"data\":["; n=0; }
/\|/ { if (n != 0)
printf ",";
gsub(" ", "", $1);
gsub(" ", "", $2);
printf "{\"{#PGBOUNCER_DATABASE}\": \"" $1 "\", \"{#PGBOUNCER_USER}\": \"" $2 "\"}";
n++; }
END { printf "]}"; }'
elif [ "x$COMMAND" = "xtotals" ]
then
# get total statistic
psql -h $PGBOUNCER_HOST -p $PGBOUNCER_PORT -U $MON_USER pgbouncer -t -c 'show totals;'
elif [ "x$COMMAND" = "xstats" ]
then
# get statistic per db
psql -h $PGBOUNCER_HOST -p $PGBOUNCER_PORT -U $MON_USER pgbouncer -t -c 'show stats;'
elif [ "x$COMMAND" = "xlists" ]
then
# get internal information
psql -h $PGBOUNCER_HOST -p $PGBOUNCER_PORT -U $MON_USER pgbouncer -t -c 'show lists;'
elif [ "x$COMMAND" = "xpools" ]
then
# get pools statistic
psql -h $PGBOUNCER_HOST -p $PGBOUNCER_PORT -U $MON_USER pgbouncer -t -c 'show pools;'
fi