Skip to content

Commit ee34713

Browse files
committed
Merge branch 'master' of github.com:pgexperts/pgx_scripts
2 parents f63ad29 + c0a62a1 commit ee34713

File tree

1 file changed

+45
-17
lines changed

1 file changed

+45
-17
lines changed

pgbouncer/log_pgbouncer_stats.sh

100644100755
Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,59 @@ NUMMIN=${1:-60}
66
NUMMIN=$(($NUMMIN * 2 + 10))
77
CURMIN=0
88

9-
export PGUSER=pgbouncer
10-
export PGPASSWORD=
11-
export PGHOST=127.0.0.1
12-
export PGDATABASE=pgbouncer
9+
# If you want to hard-code these, uncomment them.
10+
# Otherwise just set these variables in your
11+
# shell before running this command, using the
12+
# same three lines listed below.
13+
#
14+
# If you need to set a password, use ~/.pgpass:
15+
# http://www.postgresql.org/docs/9.3/static/libpq-pgpass.html
16+
17+
#export PGUSER=pgbouncer
18+
#export PGDATABASE=pgbouncer
19+
#export PGPORT=6542
20+
21+
PSFILE="ps-scratch.txt"
22+
STOPFILE="./stopfile"
23+
clean_up_and_exit() {
24+
echo 'Caught interrupt; exiting'
25+
rm $PSFILE
26+
rm -f "$STOPFILE"
27+
exit $?
28+
}
29+
trap "echo 'Caught interrupt; exiting'; clean_up_and_exit" SIGINT
30+
31+
32+
log_resource_usage() {
33+
ps -eo pid,pcpu,pmem,rss,vsz,args > $PSFILE
34+
grep '/usr/lib/postgresql/9.3/bin/postgres -D' $PSFILE | adddate >> ps.log
35+
grep '/usr/sbin/pgbouncer' $PSFILE | adddate >> ps.log
36+
}
1337

1438
adddate() {
15-
DTSTAMP=$(date +"%Y-%m-%d %H:%M:%S")
39+
DTSTAMP=$(date +"%Y-%m-%d %H:%M:%S %z")
1640
while IFS= read -r line; do
17-
echo "$DTSTAMP|$line"
41+
echo "$DTSTAMP $line"
1842
done
1943
}
2044

21-
while [ $CURMIN -lt $NUMMIN ]
45+
while [ $CURMIN -lt $NUMMIN ]
2246
do
2347

24-
psql -q -A -t -c "show pools" | adddate >> pools.log
25-
26-
psql -q -A -t -c "show stats" | adddate >> stats.log
27-
28-
psql -q -A -t -c "show clients" | adddate >> clients.log
48+
psql -q -A -t -F " " -c "show pools" | adddate >> pools.log
49+
psql -q -A -t -F " " -c "show stats" | adddate >> stats.log
50+
psql -q -A -t -F " " -c "show clients" | adddate >> clients.log
51+
52+
log_resource_usage
2953

30-
#cycle twice per minute
31-
sleep 30
32-
let CURMIN=CURMIN+1
33-
54+
if [[ -e "$STOPFILE" ]]; then
55+
echo "Exiting; detected '$STOPFILE'"
56+
clean_up_and_exit
57+
else
58+
#cycle twice per minute
59+
sleep 30
60+
let CURMIN=CURMIN+1
61+
fi
3462
done
3563

36-
exit 0
64+
clean_up_and_exit

0 commit comments

Comments
 (0)