Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / postgresql / postgresql_active_backends @ 17f78427

Historique | Voir | Annoter | Télécharger (1,6 ko)

1 e3ecbdf9 Guilherme Augusto da Rocha Silva
#!/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 fba800ae Veres Lajos
#    Recommended user is PostgreSQL database owner (default: postgres).
20 e3ecbdf9 Guilherme Augusto da Rocha Silva
#
21
# Log info:
22
# 2007/11/30 - Review on comments
23 9765abcb Dave Fennell
# 2012/12/19 - Updated to connect locally instead of localhost by default
24
#              (PostgreSQL has different permissions for these).
25 e3ecbdf9 Guilherme Augusto da Rocha Silva
#
26
27 9765abcb Dave Fennell
dbserver='' #'-h hostname'
28 e3ecbdf9 Guilherme Augusto da Rocha Silva
dbuser='postgres'
29
30
if [ "$1" = "config" ]; then
31 9765abcb Dave Fennell
   maximum=$(psql ${dbserver} -U ${dbuser} -tc "SHOW max_connections;" | bc)
32
   reserved=$(psql ${dbserver} -U ${dbuser} -tc "SHOW superuser_reserved_connections;" | bc)
33 e3ecbdf9 Guilherme Augusto da Rocha Silva
   warning=$(((maximum-reserved)*70/100))
34
   critical=$(((maximum-reserved)*90/100))
35
   echo 'graph_args --base 1000 --lower-limit 0 --upper-limit '${maximum}
36 29bdf34e dipohl
   echo 'graph_category db'
37 e3ecbdf9 Guilherme Augusto da Rocha Silva
   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 9765abcb Dave Fennell
echo 'backends.value '$(psql ${dbserver} -U ${dbuser} -tc "SELECT SUM(numbackends) FROM pg_stat_database;" | bc)