ncc.zabbix_templates
2023-10-29
ncc.zabbix_templates/pgBouncer/res/pgbouncer.sh
+ Шаблон для PgBouncer
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/pgBouncer/res/pgbouncer.sh Sun Oct 29 16:02:48 2023 +0300 1.3 @@ -0,0 +1,46 @@ 1.4 +#!/bin/sh 1.5 +# devel.a0fs.ru -- ncc.zabbix_templates/pgbouncer/res/pgbouncer.sh -- v0.r202310.1 # 1.6 + 1.7 +export HOME=/etc/zabbix/scripts-data/pgbouncer 1.8 + 1.9 +PGBOUNCER_HOST=$(head -n 1 /etc/zabbix/scripts-data/pgbouncer/.pgpass |cut -d: -f1) 1.10 +PGBOUNCER_PORT=$(head -n 1 /etc/zabbix/scripts-data/pgbouncer/.pgpass |cut -d: -f2) 1.11 +MON_USER=$(head -n 1 /etc/zabbix/scripts-data/pgbouncer/.pgpass |cut -d: -f4) 1.12 + 1.13 +COMMAND=$1 1.14 +#USER=$3 1.15 +#DB=$2 1.16 + 1.17 +if [ "x$COMMAND" = "xdiscover" ] 1.18 +then 1.19 + # discovery bases and users 1.20 + psql -h $PGBOUNCER_HOST -p $PGBOUNCER_PORT -U $MON_USER pgbouncer -t -c 'show pools;' \ 1.21 + | awk -F'|' 'BEGIN { printf "{\"data\":["; n=0; } 1.22 + /\|/ { if (n != 0) 1.23 + printf ","; 1.24 + gsub(" ", "", $1); 1.25 + gsub(" ", "", $2); 1.26 + printf "{\"{#PGBOUNCER_DATABASE}\": \"" $1 "\", \"{#PGBOUNCER_USER}\": \"" $2 "\"}"; 1.27 + n++; } 1.28 + END { printf "]}"; }' 1.29 +elif [ "x$COMMAND" = "xtotals" ] 1.30 +then 1.31 + # get total statistic 1.32 + psql -h $PGBOUNCER_HOST -p $PGBOUNCER_PORT -U $MON_USER pgbouncer -t -c 'show totals;' 1.33 + 1.34 +elif [ "x$COMMAND" = "xstats" ] 1.35 +then 1.36 + # get statistic per db 1.37 + psql -h $PGBOUNCER_HOST -p $PGBOUNCER_PORT -U $MON_USER pgbouncer -t -c 'show stats;' 1.38 + 1.39 +elif [ "x$COMMAND" = "xlists" ] 1.40 +then 1.41 + # get internal information 1.42 + psql -h $PGBOUNCER_HOST -p $PGBOUNCER_PORT -U $MON_USER pgbouncer -t -c 'show lists;' 1.43 + 1.44 +elif [ "x$COMMAND" = "xpools" ] 1.45 +then 1.46 + # get pools statistic 1.47 + psql -h $PGBOUNCER_HOST -p $PGBOUNCER_PORT -U $MON_USER pgbouncer -t -c 'show pools;' 1.48 + 1.49 +fi 1.50 \ No newline at end of file