From e3ecbdf91132d23c8868e4826c6f5b99a6e29d32 Mon Sep 17 00:00:00 2001 From: Guilherme Augusto da Rocha Silva Date: Fri, 30 Nov 2007 12:43:29 +0100 Subject: [PATCH] Initial version --- plugins/other/postgresql_active_backends | 49 ++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 plugins/other/postgresql_active_backends diff --git a/plugins/other/postgresql_active_backends b/plugins/other/postgresql_active_backends new file mode 100755 index 00000000..225e0d35 --- /dev/null +++ b/plugins/other/postgresql_active_backends @@ -0,0 +1,49 @@ +#!/bin/bash +# +# Plugin to monitor PostgreSQL Backends +# +# Author: +# Guilherme Augusto da Rocha Silva +# +# 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 +# + +dbserver='localhost' +dbuser='postgres' + +if [ "$1" = "config" ]; then + maximum=$(psql -h ${dbserver} -U ${dbuser} -tc "SHOW max_connections;" | bc) + reserved=$(psql -h ${dbserver} -U ${dbuser} -tc "SHOW superuser_reserved_connections;" | bc) + 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 + +echo 'backends.value '$(psql -h ${dbserver} -U ${dbuser} -tc "SELECT SUM(numbackends) FROM pg_stat_database;" | bc)