root / plugins / postgresql / postgresql_active_backends @ e15ed8cb
Historique | Voir | Annoter | Télécharger (1,61 ko)
| 1 |
#!/bin/bash |
|---|---|
| 2 |
# |
| 3 |
# Plugin to monitor PostgreSQL Backends |
| 4 |
# |
| 5 |
# Author: |
| 6 |
# Guilherme Augusto da Rocha Silva <gars.dba@gmail.com> |
| 7 |
# |
| 8 |
# Created: |
| 9 |
# 5th of november 2007 |
| 10 |
# |
| 11 |
# Usage: |
| 12 |
# Place in /etc/munin/plugins/ (or link it there using ln -s) |
| 13 |
# |
| 14 |
# Parameters: |
| 15 |
# config (required) |
| 16 |
# |
| 17 |
# General info: |
| 18 |
# Require permission for database access and read (no writes are processed). |
| 19 |
# Recomended user is PostgreSQL database owner (default: postgres). |
| 20 |
# |
| 21 |
# Log info: |
| 22 |
# 2007/11/30 - Review on comments |
| 23 |
# 2012/12/19 - Updated to connect locally instead of localhost by default |
| 24 |
# (PostgreSQL has different permissions for these). |
| 25 |
# |
| 26 |
|
| 27 |
dbserver='' #'-h hostname' |
| 28 |
dbuser='postgres' |
| 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 |
echo 'graph_args --base 1000 --lower-limit 0 --upper-limit '${maximum}
|
| 36 |
echo 'graph_category Postgresql' |
| 37 |
echo 'graph_info Shows open backends on the PostgreSQL Server.' |
| 38 |
echo 'graph_scale no' |
| 39 |
echo 'graph_title PostgreSQL Active Backends' |
| 40 |
echo 'graph_vlabel Number of active backends' |
| 41 |
echo 'backends.label backends' |
| 42 |
echo 'backends.type GAUGE' |
| 43 |
echo 'backends.min 0' |
| 44 |
echo 'backends.max '${maximum}
|
| 45 |
echo 'backends.warning '${warning}
|
| 46 |
echo 'backends.critical '${critical}
|
| 47 |
echo 'backends.info Number of open sessions.' |
| 48 |
exit 0 |
| 49 |
fi |
| 50 |
|
| 51 |
echo 'backends.value '$(psql ${dbserver} -U ${dbuser} -tc "SELECT SUM(numbackends) FROM pg_stat_database;" | bc)
|
