root / plugins / postgresql / postgresql_active_backends_by_database @ e15ed8cb
Historique | Voir | Annoter | Télécharger (2,26 ko)
| 1 | 87728bb2 | Dave Fennell | #!/bin/bash |
|---|---|---|---|
| 2 | # |
||
| 3 | # Plugin to monitor PostgreSQL backends by database. |
||
| 4 | # (Draws a line for each database and a total with suitable warning and critical values) |
||
| 5 | # |
||
| 6 | # Author: |
||
| 7 | # Dave Fennel <dave@microtux.co.uk> |
||
| 8 | # |
||
| 9 | # Created: |
||
| 10 | # 21st Feb 2013 |
||
| 11 | # |
||
| 12 | # License: |
||
| 13 | # GPLv2 |
||
| 14 | # |
||
| 15 | # Usage: |
||
| 16 | # Place in /etc/munin/plugins/ (or link it there using ln -s) |
||
| 17 | # |
||
| 18 | # General info: |
||
| 19 | # Requires permission for database access and read (no writes are processed). |
||
| 20 | # Recomended user is PostgreSQL database owner (default: postgres). |
||
| 21 | # |
||
| 22 | |||
| 23 | dbserver='' # '-h localhost' |
||
| 24 | dbuser='postgres' |
||
| 25 | |||
| 26 | # The psql command to use. |
||
| 27 | cmd="psql ${dbserver} -U ${dbuser} -tc 'SELECT datname,numbackends FROM pg_stat_database;' | grep -v '^$'"
|
||
| 28 | |||
| 29 | |||
| 30 | if [ "$1" = "config" ]; then |
||
| 31 | maximum=$(psql ${dbserver} -U ${dbuser} -tc "SHOW max_connections;" | bc)
|
||
| 32 | reserved=$(psql ${dbserver} -U ${dbuser} -tc "SHOW superuser_reserved_connections;" | bc)
|
||
| 33 | warning=$(((maximum-reserved)*70/100)) |
||
| 34 | critical=$(((maximum-reserved)*90/100)) |
||
| 35 | |||
| 36 | echo 'graph_args --base 1000 --lower-limit 0' # --upper-limit '${maximum}
|
||
| 37 | echo 'graph_category Postgresql' |
||
| 38 | echo 'graph_info Shows open backends for each database on the server' |
||
| 39 | echo 'graph_scale no' |
||
| 40 | echo 'graph_title PostgreSQL Active Backends By Database' |
||
| 41 | echo 'graph_vlabel Number of active backends' |
||
| 42 | |||
| 43 | pools="" |
||
| 44 | |||
| 45 | while read pool sep backends junk |
||
| 46 | do |
||
| 47 | test -z "${pool}" && continue
|
||
| 48 | |||
| 49 | # Skip pgbouncer database itself. |
||
| 50 | if [ "$pool" = "template0" ]; then |
||
| 51 | continue |
||
| 52 | fi |
||
| 53 | |||
| 54 | if [ "$pool" = "template1" ]; then |
||
| 55 | continue |
||
| 56 | fi |
||
| 57 | |||
| 58 | echo ${pool}.label ${pool}
|
||
| 59 | echo ${pool}.info ${pool} active backends
|
||
| 60 | echo ${pool}.draw LINE2
|
||
| 61 | |||
| 62 | pools="${pools} $pool"
|
||
| 63 | |||
| 64 | done < <(eval ${cmd})
|
||
| 65 | |||
| 66 | echo total.label total |
||
| 67 | echo total.info total active backends |
||
| 68 | echo total.draw AREA |
||
| 69 | echo total.colour AFCACA |
||
| 70 | echo total.sum ${pools}
|
||
| 71 | echo total.warning ${warning}
|
||
| 72 | echo total.critical ${critical}
|
||
| 73 | |||
| 74 | # If dirty config capability is enabled then fall through |
||
| 75 | # to output the data with the config information. |
||
| 76 | if [ "$MUNIN_CAP_DIRTYCONFIG" = "" ]; then |
||
| 77 | exit 0 |
||
| 78 | fi |
||
| 79 | fi |
||
| 80 | |||
| 81 | while read pool sep backends junk |
||
| 82 | do |
||
| 83 | test -z "${pool}" && continue
|
||
| 84 | |||
| 85 | # Skip template databases. |
||
| 86 | if [ "$pool" = "template0" ]; then |
||
| 87 | continue |
||
| 88 | fi |
||
| 89 | |||
| 90 | if [ "$pool" = "template1" ]; then |
||
| 91 | continue |
||
| 92 | fi |
||
| 93 | |||
| 94 | echo ${pool}.value ${backends}
|
||
| 95 | |||
| 96 | done < <(eval ${cmd}) |
