2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00
contrib-munin/plugins/postgresql/postgresql_active_locks

60 lines
1.4 KiB
Plaintext
Raw Normal View History

2007-11-30 12:45:21 +01:00
#!/bin/bash
#
# Plugin to monitor PostgreSQL Locks
#
# Author:
# Guilherme Augusto da Rocha Silva <gars.dba@gmail.com>
#
# Created:
# 5th of november 2007
#
# Modified:
# 22th of September 2011 by Nozomu Kaneko <nozom.kaneko@gmail.com>
#
2007-11-30 12:45:21 +01:00
# 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).
# Recommended user is PostgreSQL database owner (default: postgres).
2007-11-30 12:45:21 +01:00
#
# Log info:
#
dbserver='localhost'
dbuser='postgres'
modes="AccessExclusive AccessShare Exclusive RowExclusive RowShare Share ShareRowExclusive ShareUpdateExclusive"
2007-11-30 12:45:21 +01:00
if [ "$1" = "config" ]; then
echo 'graph_args --lower-limit 0'
echo 'graph_category db'
2007-11-30 12:45:21 +01:00
echo 'graph_info Shows active locks on database server.'
echo 'graph_scale no'
echo 'graph_title PostgreSQL Active Locks'
echo 'graph_vlabel Number of active locks'
for mode in $modes; do
echo $mode.label $mode
echo $mode.info `echo $mode | perl -pe 's/(.)([A-Z])/$1 $2/g'` Lock.
done
2007-11-30 12:45:21 +01:00
exit 0
fi
for mode in $modes; do
eval ${mode}=0
done
eval $(psql -h ${dbserver} -U ${dbuser} template1 -tc "SELECT trim(mode, 'Lock'), COUNT(*) FROM pg_locks GROUP BY mode ORDER BY 1;" | while read name sep num
2007-11-30 12:45:21 +01:00
do
test -z "${name}" && continue
echo ${name}=${num}
done)
for mode in $modes; do
2011-09-22 18:17:58 +02:00
echo ${mode}.value $(eval echo \$$mode)
2007-11-30 12:45:21 +01:00
done