plugin-pg_diskusage: pg_diskusage

File pg_diskusage, 1.4 kB (added by anonymous, 6 years ago)
Line 
1 #!/bin/sh
2 #
3 # Script to monitor disk usage of PostgreSQL databases.
4 # Requires oid2name, usually bundled in some "contrib" package.
5 # Most likely requires to be run as postgresql user or root.
6 #
7 # Tested with PostgreSQL 8.0, 8.1
8 #
9 # Parameters understood:
10 #
11 #       config   (required)
12 #       autoconf (optional - used by munin-config)
13 #
14 #
15 # Magic markers (optional - used by munin-config and installation
16 # scripts):
17 #
18 #%# family=auto
19 #%# capabilities=autoconf
20
21 OID2NAME=/usr/bin/oid2name
22 ARGS='-U postgres -q'
23 PGDATA=/var/lib/pgsql/data/base/
24
25 if [ "$1" = "autoconf" ]; then
26     if ( $OID2NAME $ARGS -s 2>/dev/null >/dev/null ); then
27         echo yes
28         exit 0
29     else
30         if [ $? -eq 127 ]
31             then
32             echo "no (oid2name program not found)"
33             exit 1
34         else
35             echo no
36             exit 1
37         fi
38     fi
39 fi
40
41 cd ${PGDATA}
42
43 if [ "$1" = "config" ]; then
44
45     echo 'graph_title PostgreSQL filesystem usage'
46     echo 'graph_args -l 0'
47     echo 'graph_vlabel bytes'
48     echo 'graph_category PostgreSQL'
49     echo 'graph_info This graph shows disk usage of each PostgreSQL database.'
50     $OID2NAME $ARGS | while read OID DBNAME OPT; do
51         echo "$DBNAME.label $DBNAME"
52         echo "$DBNAME.info OID $OID"
53         echo "$DBNAME.warning 5000000000"
54         echo "$DBNAME.critical 10000000000"
55     done
56 fi
57
58 $OID2NAME $ARGS | while read OID DBNAME OPT; do
59     echo -n "$DBNAME.value "
60     echo `du -bs $OID` | awk '{ print $1 }'
61 done