2007-11-30 12:43:29 +01:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# Plugin to monitor PostgreSQL Backends
|
|
|
|
#
|
|
|
|
# Author:
|
|
|
|
# Guilherme Augusto da Rocha Silva <gars.dba@gmail.com>
|
|
|
|
#
|
|
|
|
# Created:
|
|
|
|
# 5th of november 2007
|
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
# Place in /etc/munin/plugins/ (or link it there using ln -s)
|
|
|
|
#
|
|
|
|
# Parameters:
|
|
|
|
# config (required)
|
|
|
|
#
|
|
|
|
# General info:
|
|
|
|
# Require permission for database access and read (no writes are processed).
|
|
|
|
# Recomended user is PostgreSQL database owner (default: postgres).
|
|
|
|
#
|
|
|
|
# Log info:
|
|
|
|
# 2007/11/30 - Review on comments
|
2013-02-22 17:49:21 +01:00
|
|
|
# 2012/12/19 - Updated to connect locally instead of localhost by default
|
|
|
|
# (PostgreSQL has different permissions for these).
|
2007-11-30 12:43:29 +01:00
|
|
|
#
|
|
|
|
|
2013-02-22 17:49:21 +01:00
|
|
|
dbserver='' #'-h hostname'
|
2007-11-30 12:43:29 +01:00
|
|
|
dbuser='postgres'
|
|
|
|
|
|
|
|
if [ "$1" = "config" ]; then
|
2013-02-22 17:49:21 +01:00
|
|
|
maximum=$(psql ${dbserver} -U ${dbuser} -tc "SHOW max_connections;" | bc)
|
|
|
|
reserved=$(psql ${dbserver} -U ${dbuser} -tc "SHOW superuser_reserved_connections;" | bc)
|
2007-11-30 12:43:29 +01:00
|
|
|
warning=$(((maximum-reserved)*70/100))
|
|
|
|
critical=$(((maximum-reserved)*90/100))
|
|
|
|
echo 'graph_args --base 1000 --lower-limit 0 --upper-limit '${maximum}
|
|
|
|
echo 'graph_category Postgresql'
|
|
|
|
echo 'graph_info Shows open backends on the PostgreSQL Server.'
|
|
|
|
echo 'graph_scale no'
|
|
|
|
echo 'graph_title PostgreSQL Active Backends'
|
|
|
|
echo 'graph_vlabel Number of active backends'
|
|
|
|
echo 'backends.label backends'
|
|
|
|
echo 'backends.type GAUGE'
|
|
|
|
echo 'backends.min 0'
|
|
|
|
echo 'backends.max '${maximum}
|
|
|
|
echo 'backends.warning '${warning}
|
|
|
|
echo 'backends.critical '${critical}
|
|
|
|
echo 'backends.info Number of open sessions.'
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2013-02-22 17:49:21 +01:00
|
|
|
echo 'backends.value '$(psql ${dbserver} -U ${dbuser} -tc "SELECT SUM(numbackends) FROM pg_stat_database;" | bc)
|