Projet

Général

Profil

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

root / plugins / postgresql / postgresql_database_ratio @ 8f7c72c2

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

1 97977383 Guilherme Augusto da Rocha Silva
#!/bin/bash
2
#
3
# Plugin to monitor PostgreSQL Database Ratios (blocks read X blocks hit)
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
#
24
25
dbserver='localhost'
26
dbuser='postgres'
27
28
if [ "$1" = "config" ]; then
29
   echo 'graph_args --base 1000 --lower-limit 0 --upper-limit 100'
30
   echo 'graph_category Postgresql'
31
   echo 'graph_info Shows each database read/hit (%) on the PostgreSQL Server.'
32
   echo 'graph_scale no'
33
   echo 'graph_title PostgreSQL Database Hit/Read Ratios'
34
   echo 'graph_vlabel % of blocks read and hits'
35
36
   psql -h ${dbserver} -U ${dbuser} -tc "SELECT datname FROM pg_stat_database WHERE datname != 'template0' ORDER BY 1;" | while read name
37
   do
38
      test -z "${name}" && continue
39
      echo ${name}'.label '${name}
40
      echo ${name}'.type GAUGE'
41
      echo ${name}'.min 0'
42
      echo ${name}'.max 100'
43
      if [ "${name}" == "template0" ]; then
44
         echo ${name}'.info PostgreSQL template database.'
45
      elif [ "${name}" == "template1" ]; then
46
         echo ${name}'.info PostgreSQL and/or user template database.'
47
      elif [ "${name}" == "postgres" ]; then
48
         echo ${name}'.info User postgres database.'
49
      else
50
         echo ${name}'.info User defined database.'
51
         echo ${name}'.critical 50:min'
52
         echo ${name}'.warning 75:min'
53
      fi
54
   done
55
   exit 0
56
fi
57 9765abcb Dave Fennell
psql -h ${dbserver} -U ${dbuser} -tc "SELECT datname||'.value '||(CASE WHEN (blks_hit > 0) THEN ROUND((blks_hit::NUMERIC / (blks_hit + blks_read)::NUMERIC) * 100, 2) ELSE 0 END)::TEXT FROM pg_stat_database WHERE datname != 'template0' ORDER BY datname;"