├── .gitattributes ├── .pgpass.j2 ├── README.md ├── pgbouncer.sh ├── zabbix_agentd.d └── pgbouncer.conf └── zbx_templates └── Template App PgBouncer.xml /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.pgpass.j2: -------------------------------------------------------------------------------- 1 | 127.0.0.1:6432:*:zabbix:zabbix 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Description 2 | Check PgBouncer status and LLD pools. 3 | Check pools metrics. 4 | 5 | ![pgbouncer](https://user-images.githubusercontent.com/12905969/84354505-2da9fa00-abeb-11ea-8a54-92a6aaf2ea3a.png) 6 | 7 | 8 | # Dependencies 9 | psql, bash, zabbix-agent. 10 | 11 | Installation 12 | ============ 13 | 0. configure pgbouncer monitoring user (https://www.pgbouncer.org/usage.html) 14 | 15 | 1. create directory and copy pgbouncer.sh to /var/lib/zabbix/externalscripts/ 16 | change homedir for zabbix user usermod -d /var/lib/zabbix zabbix 17 | 2. copy zabbix_agentd.d/pgbouncer.conf to /etc/zabbix/zabbix_agentd.d/ 18 | 3. chmod 755 /var/lib/zabbix/externalscripts/pgbouncer.sh and chown zabbix.zabbix /var/lib/zabbix/externalscripts/pgbouncer.sh 19 | 4. copy file .pgpass.j2 to ~zabbix/.pgpass and edit monitoring user and password, if needed, port too. 20 | 5. chmod 0600 ~zabbix/.pgpass and chown zabbix.zabbix ~zabbix/.pgpass 21 | 6. restart zabbix-agent daemon. 22 | 7. import "zbx_templates/Template App PgBouncer.xml" into your templates. 23 | 8. apply template "Template App PgBouncer" to pgbouncer node. 24 | 9. enjoy. 25 | 26 | 27 | PS 28 | =========== 29 | You can easily change the settings for monitoring a remote pgbouncer node. 30 | 31 | -------------------------------------------------------------------------------- /pgbouncer.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | PGBOUNCER_HOST=$(head -n 1 ~zabbix/.pgpass |cut -d: -f1) 4 | PGBOUNCER_PORT=$(head -n 1 ~zabbix/.pgpass |cut -d: -f2) 5 | MON_USER=$(head -n 1 ~zabbix/.pgpass |cut -d: -f4) 6 | 7 | COMMAND=$1 8 | #USER=$3 9 | #DB=$2 10 | 11 | if [ "x$COMMAND" = "xdiscover" ] 12 | then 13 | # discovery bases and users 14 | psql -h $PGBOUNCER_HOST -p $PGBOUNCER_PORT -U $MON_USER pgbouncer -t -c 'show pools;' \ 15 | | awk -F'|' 'BEGIN { printf "{\"data\":["; n=0; } 16 | /\|/ { if (n != 0) 17 | printf ","; 18 | gsub(" ", "", $1); 19 | gsub(" ", "", $2); 20 | printf "{\"{#PGBOUNCER_DATABASE}\": \"" $1 "\", \"{#PGBOUNCER_USER}\": \"" $2 "\"}"; 21 | n++; } 22 | END { printf "]}"; }' 23 | elif [ "x$COMMAND" = "xtotals" ] 24 | then 25 | # get total statistic 26 | psql -h $PGBOUNCER_HOST -p $PGBOUNCER_PORT -U $MON_USER pgbouncer -t -c 'show totals;' 27 | 28 | elif [ "x$COMMAND" = "xstats" ] 29 | then 30 | # get statistic per db 31 | psql -h $PGBOUNCER_HOST -p $PGBOUNCER_PORT -U $MON_USER pgbouncer -t -c 'show stats;' 32 | 33 | elif [ "x$COMMAND" = "xlists" ] 34 | then 35 | # get internal information 36 | psql -h $PGBOUNCER_HOST -p $PGBOUNCER_PORT -U $MON_USER pgbouncer -t -c 'show lists;' 37 | 38 | elif [ "x$COMMAND" = "xpools" ] 39 | then 40 | # get pools statistic 41 | psql -h $PGBOUNCER_HOST -p $PGBOUNCER_PORT -U $MON_USER pgbouncer -t -c 'show pools;' 42 | 43 | fi 44 | -------------------------------------------------------------------------------- /zabbix_agentd.d/pgbouncer.conf: -------------------------------------------------------------------------------- 1 | UserParameter=pgbouncer.pool.discover,/var/lib/zabbix/externalscripts/pgbouncer.sh discover 2 | UserParameter=pgbouncer.pool.totals,/var/lib/zabbix/externalscripts/pgbouncer.sh totals 3 | UserParameter=pgbouncer.pool.stats,/var/lib/zabbix/externalscripts/pgbouncer.sh stats 4 | UserParameter=pgbouncer.pool.lists,/var/lib/zabbix/externalscripts/pgbouncer.sh lists 5 | UserParameter=pgbouncer.pool.pools,/var/lib/zabbix/externalscripts/pgbouncer.sh pools 6 | -------------------------------------------------------------------------------- /zbx_templates/Template App PgBouncer.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5.0 4 | 2021-10-01T04:58:18Z 5 | 6 | 7 | Templates 8 | 9 | 10 | 11 | 1213 | 1214 | 1215 | 1216 | PgBouncer: connections 1217 | 1218 | 1219 | 199C0D 1220 | 1221 | Template App PgBouncer 1222 | pgbouncer.lists[free_clients] 1223 | 1224 | 1225 | 1226 | 1 1227 | F63100 1228 | 1229 | Template App PgBouncer 1230 | pgbouncer.lists[free_servers] 1231 | 1232 | 1233 | 1234 | 2 1235 | 2774A4 1236 | 1237 | Template App PgBouncer 1238 | pgbouncer.lists[login_clients] 1239 | 1240 | 1241 | 1242 | 3 1243 | F7941D 1244 | 1245 | Template App PgBouncer 1246 | pgbouncer.lists[used_clients] 1247 | 1248 | 1249 | 1250 | 4 1251 | FC6EA3 1252 | 1253 | Template App PgBouncer 1254 | pgbouncer.lists[used_servers] 1255 | 1256 | 1257 | 1258 | 1259 | 1260 | PgBouncer: Total data flow among all databases 1261 | 1262 | 1263 | FILLED_REGION 1264 | 00FF00 1265 | 1266 | Template App PgBouncer 1267 | pgbouncer.total.total_client_bytes 1268 | 1269 | 1270 | 1271 | 1 1272 | FILLED_REGION 1273 | 0040FF 1274 | 1275 | Template App PgBouncer 1276 | pgbouncer.total.total_server_bytes 1277 | 1278 | 1279 | 1280 | 1281 | 1282 | 1283 | --------------------------------------------------------------------------------